Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


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


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Lapses

    by Attila Szegedi,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I just can't believe I said "scratch to itch"! And I also meant to say "HtmlUnit" whenever I said "HttpUnit"; the two projects just have too similar names... HtmlUnit folks are fairly active within the Rhino community; it's definitely their project I had in mind. We don't hear much from HttpUnit.

  • Why JavaScript over other scripting languages

    by Mirko Nasato,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Good to see Rhino get some press. Just because e.g. Groovy and JRuby advocates are generally more vocal, it doesn't mean that JavaScript should be overlooked when choosing a scripting language for a Java application. It may in fact be the best choice in some scenarios.

    A few points from the interview:

    - Many (web) developers are already familiar with JavaScript; this makes it a good choice for making an app extensible even by non-Java programmers

    - It has its own sandbox to impose security restrictions

    - It comes bundled with Sun's Java 6 implementation

  • Apache Sling does use javascript for both server-side and client-side code

    by Bertrand Delacretaz,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Shameless plug: Apache Sling allows web applications to be developed entirely in javascript, both server-side using our Rhino-based ECMAscript Pages (ESP), client side based on JST templates using a JSP-like syntax to generate client javascript code, or using traditional client-side javascript libraries to access the RESTful Sling interface.

    Sling is a fairly new project, and is still evolving quite a lot, so anyone who wants to have a look at it is very welcome.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p