Skip to content

Instantly share code, notes, and snippets.

@baontq
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baontq/8a81ae3a0d8bc5edf3cd to your computer and use it in GitHub Desktop.
Save baontq/8a81ae3a0d8bc5edf3cd to your computer and use it in GitHub Desktop.
Concurrency issue of JRuby ScriptingContainer (LocalContextScope.CONCURRENT)
/**
* This will prove the concurrency issue of ScriptingContainer(JRuby) if
* more than 1 thread trying to construct ScriptingContainer instance
*
* Require jruby jar to run this.
*
* @author btran
*
*/
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.jruby.embed.LocalContextScope;
import org.jruby.embed.LocalVariableBehavior;
import org.jruby.embed.ScriptingContainer;
public class JRubyConcurrencyFailureTest {
public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(100);
for(int i=0; i < 2; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
//Will throw NullPointerException if 2 threads construct at the same time...
new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.TRANSIENT, false);
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment