0

我正在使用 Groovy 1.7.8。并编写了我在不同域对象上同时执行的 Groovy DSL。

最近,当 DSL 并发编译/执行时,我开始面临重并发下的死锁。

我在运行时编译/执行 Groovy DSL,使用:

Script s = compileScript(dsl)
def binding = new Binding()
binding.setVariable("domainObj", domainObj)
s.setBinding(binding)
s.run() 

def Script compileScript(String dsl) {
    def scriptText = getScriptText(dsl)
    def conf = new CompilerConfiguration()
    conf.setScriptBaseClass(GroovyViewExecutionBase.class.getName())
    new GroovyShell(conf).parse(scriptText)
}

下面是死锁线程的线程转储,看线程转储我感觉Groovy内部是在我们在运行时并发编译/执行脚本的时候死锁的。

死锁参与者 1:

at java.beans.PropertyDescriptor.getReadMethod(PropertyDescriptor.java:158)

- waiting to lock <0x00007f41a3363960> (a java.beans.PropertyDescriptor)

at java.beans.Introspector.processPropertyDescriptors(Introspector.java:683)

at java.beans.Introspector.getTargetPropertyInfo(Introspector.java:615)

at java.beans.Introspector.getBeanInfo(Introspector.java:407)

at java.beans.Introspector.getBeanInfo(Introspector.java:164)

- locked <0x00007f41a3358c28> (a java.lang.Object)

at groovy.lang.MetaClassImpl$15.run(MetaClassImpl.java:2940)

at java.security.AccessController.doPrivileged(Native Method)

at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:2938)

at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:2921)

- locked <0x00007f429f011268> (a groovy.lang.ExpandoMetaClass)

at groovy.lang.ExpandoMetaClass.initialize(ExpandoMetaClass.java:463)

- locked <0x00007f429f011268> (a groovy.lang.ExpandoMetaClass)

at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:166)

at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:182)

at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:210)

at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:751)

at groovy.lang.GroovyObjectSupport.<init>(GroovyObjectSupport.java:32)

at groovy.lang.Script.<init>(Script.java:40)

at groovy.lang.Script.<init>(Script.java:37)

at flipkart.cms.views.core.GroovyViewExecutionBase.<init>(GroovyViewExecutionBase.groovy)

at Script1.<init>(Script1.groovy)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

at java.lang.Class.newInstance0(Class.java:355)

at java.lang.Class.newInstance(Class.java:308)

at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:408)

at groovy.lang.GroovyShell.parse(GroovyShell.java:743)

at groovy.lang.GroovyShell.parse(GroovyShell.java:770)

at groovy.lang.GroovyShell.parse(GroovyShell.java:761)

at groovy.lang.GroovyShell$parse.call(Unknown Source)

at cms.views.core.GroovyDSLViewComputer.compileScript(GroovyDSLViewComputer.groovy:85)

===================

死锁参与者 2:在 java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1277)

- waiting to lock <0x00007f41a3358c28> (a java.lang.Object)

at java.beans.Introspector.internalFindMethod(Introspector.java:1312)

at java.beans.Introspector.findMethod(Introspector.java:1383)

at java.beans.Introspector.findMethod(Introspector.java:1363)

at java.beans.PropertyDescriptor.getReadMethod(PropertyDescriptor.java:179)

- locked <0x00007f41a3363960> (a java.beans.PropertyDescriptor)

at groovy.lang.MetaClassImpl.applyPropertyDescriptors(MetaClassImpl.java:2215)

at groovy.lang.MetaClassImpl.setupProperties(MetaClassImpl.java:1995)

at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:2950)

at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:2921)

- locked <0x00007f42a12972b8> (a groovy.lang.ExpandoMetaClass)

at groovy.lang.ExpandoMetaClass.initialize(ExpandoMetaClass.java:463)

- locked <0x00007f42a12972b8> (a groovy.lang.ExpandoMetaClass)

at org.codehaus.groovy.runtime.HandleMetaClass.replaceDelegate(HandleMetaClass.java:66)

at org.codehaus.groovy.runtime.HandleMetaClass.setProperty(HandleMetaClass.java:91)

at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:179)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:483)

at flipkart.cms.views.core.GroovyViewExecutionBase.setupAttrProperties(GroovyViewExecutionBase.groovy:60)

at flipkart.cms.views.core.GroovyViewExecutionBase$setupAttrProperties$0.callCurrent(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)

at cms.views.core.GroovyViewExecutionBase.computeView(GroovyViewExecutionBase.groovy:32)

===================

有什么想法可以解决/解决这个问题吗?

4

1 回答 1

1

将此发布在 groovy-user 论坛上,看起来死锁是由于 java 6 的 java.beans.Introspector 类中的同步问题引起的,该类显然已在 Java 7 中修复。还收到了这些类的 Java 6 的反向移植,并且正在测试向后移植类以重现死锁。

更多细节在这里:

http://groovy.329449.n5.nabble.com/Groovy-deadlocks-when-executing-DSL-from-GroovyShell-td5709889.html

于 2012-05-31T10:12:36.773 回答