BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Interview: Attila Szegedi Discusses Rhino

Interview: Attila Szegedi Discusses Rhino

In this interview, Attila Szegedi discusses the Rhino JavaScript engine. Topics covered include the implementation of Rhino, Rhino's featureset, continuations, usage patterns for embedding Rhino, running JavaScript on the server, scripting capabilities for Rhino, JavaScript versus Ruby, JavaScript on Rails, and future plans for Rhino.

Watch Attila Szegedi Discusses Rhino (21 minutes).

From the interview:

You started mentioning about using JavaScript in your application and you said also before that you working on projects and you wanted to use JavaScript. Can you tell us a bit about what your need was and how you solved it with JavaScript in Rhino?
Ok, my use case was something a little bit maybe exotic. I really needed to have a system that is able to run an absurd amount of concurrent processes, I think in tens of thousands at once. And you obviously can't do that with Java threads because they don't scale to ten thousand threads at any one time. But what you can do here, you can use continuations. Continuations are something that is a really nice concept but it's not really as widely used in the industry as I would like it to be widely used, and at that time there was a version of Rhino that actually had continuations, which was the Apache Cocoon, which is a private fork of Rhino. And I actually started working with then-current developers of Rhino to add this continuation support in the mainline Rhino. Basically continuations are the objects that represent your stack trace, so you can just capture a snapshot of your stack trace, save it away and then restore it and run it later, and you don't have to keep a physical thread running for that particular stack trace at all times, you can just freeze it into a database and restore it afterwards and that really allows you to scale to really any number of concurrent so to say virtual threads running at any one time.

So in your opinion what are some of the best usage patterns for embedding JavaScript within Java applications?
Well you can embed it at really many levels. There are quite a lot of projects out there that are already using JavaScript. And they are mostly server-side JavaScript embeddings, where in web application frameworks that use Rhino they typically use it as a language to implement the action parts of the controller in a model view controller framework. There is a quite renowned application framework that is named Helma, it's developed in Austria, and the Austrian national broadcasting company uses it for its websites and several other mostly Austrian and German websites are also using it for that. You can use it for testing because it is really easy to actually create mock objects. At least with Rhino you can implement Java interfaces in JavaScript, so you can really easily and quickly create mock objects for your tests and it is actually quite easy to write a little adapter that will convert your scripts into instances of JUnit test classes, so that you can run them within JUnit as just any other test. And also there are other testing frameworks out there like HTTPUnit, which is used as the test driver for web applications and it needs to simulate the full browser environment complete with JavaScript. HTTPUnit also happens to choose Rhino as its technology for implementing the JavaScript in the emulated browser basically.

Rate this Article

Adoption
Style

BT