Hello,
When you choose LocalContextScope.CONCURRENT model, thread-safety
depends on the Ruby code. If you want to make a Hash object
thread-safe, you should use java.util.concurrent.ConcuurentHashMap.
Java's map type object behaves like Ruby's Hash in Ruby code. For
example,
ScriptingContainer sc = new
ScriptingContainer(LocalContextScope.CONCURRENT);
ConcurrentHashMap myHash = new ConcurrentHashMap();
sc.put("my_hash", myHash);
on Java side. Then, my_hash is available to use on Ruby side. See my blog post:
"4. New Map proxy" of
http://yokolet.blogspot.com/2011/01/embedding-api-refinements-for-jru...
The change on Java's Maps on Ruby side is done on Java side at the
same time. If you add some new key-value pairs in Ruby code, you can
see those pairs when you are back to Java code. This is because the
reference to the Map object is given to Ruby code.
-Yoko
On Sat, Oct 27, 2012 at 11:33 AM, Marko Asplund <marko.aspl
...@gmail.com> wrote:
> Hi,
> I'm using JRuby Embed API in my Java code, where I create an object
> graph that is processed and then passed to Ruby code. This graph
> contains e.g. RubyHash and RubyArray objects.
> The Java code runs in a multi-threaded environment and I'd like to
> make sure I'm not introducing any race conditions.
> The application instantiates a single ScriptingContainer object, which
> is shared among different threads.
> sc = new ScriptingContainer(LocalContextScope.CONCURRENT);
> RubyHash/Array objects are instantiated as follows:
> RubyHash rh = new RubyHash(sc.getProvider().getRuntime());
> Here the API requires that the Ruby runtime object is passed to
> RubyHash constructor.
> Is this code thread-safe?
> Can RubyHash objects be instantiated in another way?
> marko
> ---------------------------------------------------------------------
> 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