a Java-level deadlock example

Found one Java-level deadlock:
=============================
"StartStopServicePool-5 - 5165":
waiting to lock monitor 0x0816cc20 (object 0xb37eb908, a sun.misc.Launcher$AppClassLoader),
which is held by "soxplugin"
"soxplugin":
waiting to lock monitor 0x08468ed4 (object 0xaf99edf8, a java.lang.Class),
which is held by "StartStopServicePool-5 - 5165"

Java stack information for the threads listed above:
===================================================
"StartStopServicePool-5 - 5165":
at sun.security.jca.ProviderConfig.getProvider(Unknown Source)
[color=red]- waiting to lock <0xb37eb908> (a sun.misc.Launcher$AppClassLoader)[/color] at sun.security.jca.ProviderList.loadAll(Unknown Source)
at sun.security.jca.ProviderList.removeInvalid(Unknown Source)
at sun.security.jca.Providers.getFullProviderList(Unknown Source)
[color=red]- locked <0xaf99edf8> (a java.lang.Class for sun.security.jca.Providers)[/color] at java.security.Security.getProviders(Unknown Source)
at org.apache.commons.httpclient.HttpClient.(HttpClient.java:78)
at no.axxessit.il.axxrpc.AxxRpcAdapter.(AxxRpcAdapter.java:142)
at no.axxessit.il.axxrpc.NeInfoReader.(NeInfoReader.java:71)
at no.axxessit.il.xmlrpc.XmlRpcDiscovery.connect(XmlRpcDiscovery.java:93)
at no.axxessit.im.NeDiscovery.load(NeDiscovery.java:215)
at no.axxessit.sooem.NeLoader.addNe(NeLoader.java:98)
at no.axxessit.sooem.netmodules.NetServiceFactory.connect(NetServiceFactory.java:160)
at no.axxessit.sooem.netmodules.NetServiceFactory.init(NetServiceFactory.java:141)
at no.axxessit.sooem.netmodules.NetServiceFactoryFacade.init(NetServiceFactoryFacade.java:71)
at no.axxessit.sooem.auxmodules.StartStop.processStartNet(StartStop.java:606)
at no.axxessit.sooem.plugin.request.StartStopServicePool$StartStopService.handleMessage(StartStopServicePool.java:69)
at no.axxessit.sooem.plugin.uithread.UIThread.run(UIThread.java:246)
at java.lang.Thread.run(Unknown Source)


"soxplugin":
at sun.security.jca.Providers.beginThreadProviderList(Unknown Source)
- [color=red]waiting to lock <0xaf99edf8> (a java.lang.Class for sun.security.jca.Providers)[/color] at sun.security.jca.Providers.startJarVerification(Unknown Source)
at sun.security.util.SignatureFileVerifier.(Unknown Source)
at java.util.jar.JarVerifier.processEntry(Unknown Source)
at java.util.jar.JarVerifier.update(Unknown Source)
at java.util.jar.JarFile.initializeVerifier(Unknown Source)
at java.util.jar.JarFile.getInputStream(Unknown Source)
- locked <0xb449cc40> (a java.util.jar.JarFile)
at sun.misc.URLClassPath$JarLoader$2.getInputStream(Unknown Source)
at sun.misc.Resource.cachedInputStream(Unknown Source)
- locked <0xb4bfa760> (a sun.misc.URLClassPath$JarLoader$2)
at sun.misc.Resource.getByteBuffer(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
- locked <0xb37eb908> (a sun.misc.Launcher$AppClassLoader)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[color=red]- locked <0xb37eb908> (a sun.misc.Launcher$AppClassLoader)[/color] at java.lang.ClassLoader.loadClass(Unknown Source)
at no.axxessit.nmi.notif.EventProcessor.(EventProcessor.java:44)
at no.axxessit.nmi.NMIGWImpl.initCommunicationService(NMIGWImpl.java:259)
at no.axxessit.nmi.NMIGWImpl.activateGateway(NMIGWImpl.java:153)
at no.axxessit.gw.common.fw.AbstractGatewayImpl.startup(AbstractGatewayImpl.java:35)
at no.axxessit.nmi.NMIGWImpl.startup(NMIGWImpl.java:137)
at no.axxessit.sooplugin.action.StartupBaseServiceAction.performAction(StartupBaseServiceAction.java:23)
at no.axxessit.sooplugin.action.StartupCspGatewaysAction.performAction(StartupCspGatewaysAction.java:40)
at no.axxessit.sooplugin.SooPlugin.start(SooPlugin.java:50)
at no.axxessit.sooplugin.SooPlugin.startup(SooPlugin.java:40)
at no.axxessit.common.as.BaseServiceWrapper.run(BaseServiceWrapper.java:97)
at java.lang.Thread.run(Unknown Source)
at no.axxessit.common.thread.AxxThread.safeRun(AxxThread.java:169)
at no.axxessit.common.thread.AxxThread$1.run(AxxThread.java:134)
at java.security.AccessController.doPrivileged(Native Method)
at no.axxessit.common.thread.AxxThread.run(AxxThread.java:138)

Found 1 deadlock.

Heap
PSYoungGen total 344064K, used 35831K [0xdb7e0000, 0xf37e0000, 0xf37e0000)
eden space 294912K, 12% used [0xdb7e0000,0xddadde98,0xed7e0000)
from space 49152K, 0% used [0xf07e0000,0xf07e0000,0xf37e0000)
to space 49152K, 0% used [0xed7e0000,0xed7e0000,0xf07e0000)
PSOldGen total 131072K, used 24937K [0xb37e0000, 0xbb7e0000, 0xdb7e0000)
object space 131072K, 19% used [0xb37e0000,0xb503a5d0,0xbb7e0000)
PSPermGen total 30976K, used 17511K [0xaf7e0000, 0xb1620000, 0xb37e0000)
object space 30976K, 56% used [0xaf7e0000,0xb08f9ff8,0xb1620000)

Solution 1: 让两个线程先后执行.
Solution 2: 在第一个线程里先锁ClassLoader.
ClassLoader cl = this.getClass().getClassLoader();
synchronized(cl){
}

你可能感兴趣的:(JAVA)