高负载下Java Beanshell解释器中的锁争用 [英] Lock contention in Java Beanshell interpreter under high load

查看:83
本文介绍了高负载下Java Beanshell解释器中的锁争用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在应用程序中使用Java BeanShell解释器(v1.2 b7)动态执行标准Java语法.

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

示例代码

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:

等待线程调用堆栈

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

阻塞线程调用堆栈

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

我已经检查了最新版本(v2.0 b4)的源代码,而且似乎也有相同的问题.

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

我的问题是:

  1. 有人遇到过这样的问题吗?如果是,请您提出任何可能的解决方案?
  2. 我们使用的代码是否有问题?是否不建议为每个线程创建单独的 bsh.Interpreter 实例?请注意,对于不同的线程,我们正在评估的脚本是不同的.
  3. 在Java中,BeanShell解释器是否有其他替代方法可以在高负载下正常工作?
  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?

推荐答案

如您所见,beanshell在侦听器对象上使用Vector.

As you can see beanshell uses Vector on listeners objects.

很明显,Vector的内部结构受到过度保护",请参见向量

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

BeanShell 1.3.0于2003年8月发布,版本2.0b4于2005年5月发布.

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

您可以检查最新的2.0b5 beanshell ,但我想您可以通过进行活动的项目来获得更好的收益替代为 groovy

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

这篇关于高负载下Java Beanshell解释器中的锁争用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆