Thursday Mar 06, 2014

JavaScript in the Enterprise

Nashorn is the new JavaScript engine that will ship with Java SE 8 . Under the hood, it leverages the invokedynamic bytecode introduced in Java SE 7. By doing this, Nashorn offers improved performance. It also shine when it comes to compliance with the ECMA JavaScript specification. But that's not all, Nashorn also offers a nice interoperability between Java and JavaScript. For a good overview of Nashorn, see this recent 'Oracle Nashorn: A Next-Generation JavaScript Engine for the JVM' article.

For Enterprise developers, Nashorn will offers new possibilities. For example, Avatar.js relies on Nashorn to support the Node.js programming model on the Java Virtual Machine. Project Avatar extends this model with added-value capabilities such as multiple event-loops with a built-in load-balancer; multithreading capabilities with a lightweight message passing mechanism; Model-Store, a pure JavaScript ORM based on JPA; etc.

Another way of leveraging Nashorn in the enterprise is scripting.  Instead of writing shell scripts, why not leverage JavaScript, eventually with some Java hooks if necessary? This simple script shows how to use Nashorn to monitor GlassFish via its REST Administration capabilities. This approach can easily be extended to fit any monitoring or management needs.