[jruby] Threadsafe or concurrent - which way to go?

changepoint_advi.fischer at extaccount.com changepoint_advi.fischer at extaccount.com
Wed Jan 20 01:00:16 JST 2016


I have a multithreaded application JRuby application. Part of this application is a module with variables (basically a Singleton object with state), something like this:

module MyMod
    extend self
   attr_accessor :control
   def do_something(x) {
        ....
   }
  private
  def helper1 { .... }
  def helper2 { .... }
}

While MyMod is really a singleton from the viewpoint of one single thread, but the various threads will execute MyMod.do_something(...) in parallel. The data passed into the procedure (x) is thread-local, i.e. each thread has its own copy; no danger from this side. OTOH,  the variable MyMod.control must end up thread-local too. Basically, I would like to have a separate MyMod instance per thread.

When I create the ScriptingContainer, what context scope should I use, so that I don't get any conflicts due to multi-threading in this design?  Do I have to use LocalContextScope.THREADSAFE ,  or is it safe to use LocalContextScope.CONCURRENT (which would share the Runtime between the threads)?

Ronald


If you are not the addressee, please inform us immediately that you have received this e-mail by mistake, and delete it. We thank you for your support.



More information about the JRuby mailing list