Last active
August 29, 2015 14:07
-
-
Save baontq/8a81ae3a0d8bc5edf3cd to your computer and use it in GitHub Desktop.
Concurrency issue of JRuby ScriptingContainer (LocalContextScope.CONCURRENT)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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