Lock contention in Java Beanshell interpreter under high load

倖福魔咒の 提交于 2019-12-24 07:36:00

问题


We are using Java BeanShell interpreter (v1.2 b7) in our application for dynamically executing standard Java syntax.

Sample Code

bsh.Interpreter interpreter = new bsh.Interpreter();
interpreter.set("context", ctx);
interpreter.set("transaction", transaction);
interpreter.set("log", log);
interpreter.eval(script);

We are having a problem under high load where we are seeing thread lock contention when multiple threads execute above code simultaneously. We have multiple threads in the waiting state which is degrading application performance.

Here are the call stack traces of waiting and blocked threads:

Waiting Thread Call Stack

java.util.Vector.addElement():619
bsh.classpath.ClassManagerImpl.addListener():N/A
bsh.BshClassManager.addCMListener():N/A
bsh.NameSpace.<init>():N/A
bsh.BlockNameSpace.<init>():N/A
bsh.BSHBlock.eval():N/A
bsh.BSHBlock.eval():N/A
bsh.BSHWhileStatement.eval():N/A
bsh.Interpreter.eval():N/A
bsh.Interpreter.eval():N/A
bsh.Interpreter.eval():N/A

Blocked Thread Call Stack

java.util.Vector.indexOf():408
java.util.Vector.indexOf():382
java.util.Vector.removeElement():641
bsh.classpath.ClassManagerImpl.addListener():N/A
bsh.BshClassManager.addCMListener():N/A
bsh.NameSpace.<init>():N/A
bsh.BshMethod.invokeDeclaredMethod():N/A
bsh.Name.invokeLocalMethod():N/A
bsh.Name.invokeMethod():N/A
bsh.BSHMethodInvocation.eval():N/A
bsh.BSHPrimaryExpression.eval():N/A
bsh.Interpreter.eval():N/A
bsh.Interpreter.eval():N/A
bsh.Interpreter.eval():N/A

I have checked the source code for the latest version (v2.0 b4) and it also seems to have the same issue.

My questions are:

  1. Has anyone experienced such problem? If yes, can you please suggest any possible resolution for it?
  2. Is there any problem with the code that we are using? Is it not recommended to create a separate instance of bsh.Interpreter per thread? Please note that script that we are evaluating is different for the different thread.
  3. Is there any alternative to BeanShell interpreter in Java that works well under high load?

回答1:


As you can see beanshell uses Vector on listeners objects.

Obviously Vector is "over protected" on its internals see vector

BeanShell 1.3.0 was released in August 2003, version 2.0b4 in May 2005.

You can check latest 2.0b5 beanshell but I guess you you will be better off with active projects alternative as groovy



来源:https://stackoverflow.com/questions/45450947/lock-contention-in-java-beanshell-interpreter-under-high-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!