Hi,
On JSR223, you can call terminate() method by using
"org.jruby.embed.termination" attribute.
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("jruby");
engine.eval("$x='GVar'");
engine.eval("at_exit { puts \"#{$x} in an at_exit block\" }"); //
nothing is printed here
engine.getContext().setAttribute("org.jruby.embed.termination", true,
ScriptContext.ENGINE_SCOPE);
engine.eval(""); // prints "GVar in an at_exit block"
See my blog,
http://yokolet.blogspot.com/2010/02/jruby-embed-red-bridge-update.html
On Thu, Feb 24, 2011 at 9:49 AM, Rob Heittman
<[email protected]> wrote:
> I'm porting some code from using the JRuby Embed API directly to
> JSR-223. The requirement is driven by a desire to loosely couple the
> calling code to the JRuby interpreter; if I use any JRuby classes
> directly in the caller, I lose the pluggability I need. All works
> well, save for this:
>
> Runtimes need to be discarded by the application occasionally. The
> application used to do this:
>
> JavaEmbedUtils.terminate(runtime)
>
> ... which cleaned everything up fine. But the new application just
> abandons Engines, which never go away on their own, and eventually
> exhaust memory. I'm pretty sure the javax.scripting API is lacking on
> this front. I don't think there's any lifecycle support for Engines at
> all. That's kind of OK, since I've got my own OSGi-friendly broker for
> returning ScriptEngine instances; it *does* understand lifecycle, and
> that's where I need to be able to kill off an engine that is no longer
> of any use.
I totally agree that JSR223 is lacking features for JRuby. That's why
I wrote embed core, ScriptingContainer stuff.
-Yoko
>
> So: anyone know a clever way to tell a JRuby JSR-223 ScriptEngine that
> I'm done with it? My only workable idea was to expose a public method
> on JRubyEngine, which I think has the underlying Ruby object visible,
> to terminate the runtime; I can use reflection to invoke that method
> if it exists, without introducing a hard dependency on JRuby.
>
> - Rob
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email