当前位置: 首页 > 知识库问答 >
问题:

当java.lang.Thread.State处于阻塞状态时,如何获取on对象监视器地址?

范麒
2023-03-14

所以我的问题是如何找到它等待的对象监视器\lock地址?
同时,如何防止对象监视器被JIT编译以使等待信息始终可用的JVM选项-xx:compileCommand?

顺便说一句,我在java-thread-dump-waiting-on-object-monitor-what-is-it-waiting-on中也发现了类似的问题,从JVM专家的回答中我知道丢失的“waiting on”信息可能是由JIT编译器造成的,该URL中的解决方案正好适合同步对象中的object.wait(),但是我的情况明显不同,因为它试图获取对象监视器,而不是等待从同步对象获取通知。

下面的信息是提到的两个线程的调用堆栈:

"catalina-exec-995" #1178 daemon prio=5 os_prio=0 tid=0x00007f6b7831f000 nid=0x15c0 waiting for monitor entry [0x00007f6b43ffc000]
java.lang.Thread.State: BLOCKED (on object monitor)
at java.util.zip.ZipFile.getEntry(ZipFile.java:308)
- locked <**0x000000065888b918**> (a java.util.jar.JarFile)
at java.util.jar.JarFile.getEntry(JarFile.java:240)
at java.util.jar.JarFile.getJarEntry(JarFile.java:223)
at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.getArchiveEntry(AbstractSingleArchiveResourceSet.java:94)
at org.apache.catalina.webresources.AbstractArchiveResourceSet.getResource(AbstractArchiveResourceSet.java:260)
at org.apache.catalina.webresources.StandardRoot.getResourcesInternal(StandardRoot.java:327)
at org.apache.catalina.webresources.CachedResource.validateResources(CachedResource.java:124)
- locked <0x000000068aa3c7a0> (a org.apache.catalina.webresources.CachedResource)
at org.apache.catalina.webresources.Cache.getResources(Cache.java:147)
at org.apache.catalina.webresources.StandardRoot.getResources(StandardRoot.java:315)
at org.apache.catalina.webresources.StandardRoot.getClassLoaderResources(StandardRoot.java:231)
at org.apache.catalina.loader.WebappClassLoaderBase.findResources(WebappClassLoaderBase.java:939)
at java.lang.ClassLoader.getResources(ClassLoader.java:1142)
at com.sun.jersey.spi.service.ServiceFinder.getResources(ServiceFinder.java:352)
at com.sun.jersey.spi.service.ServiceFinder.access$200(ServiceFinder.java:159)
at com.sun.jersey.spi.service.ServiceFinder$AbstractLazyIterator.setConfigs(ServiceFinder.java:720)
at com.sun.jersey.spi.service.ServiceFinder$AbstractLazyIterator.hasNext(ServiceFinder.java:732)
at com.sun.jersey.spi.service.ServiceFinder.toClassArray(ServiceFinder.java:595)
at com.sun.jersey.core.spi.component.ProviderServices.getServiceClasses(ProviderServices.java:318)
at com.sun.jersey.core.spi.component.ProviderServices.getServiceClasses(ProviderServices.java:311)
at com.sun.jersey.core.spi.component.ProviderServices.getServices(ProviderServices.java:159)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.initWriters(MessageBodyFactory.java:207)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:163)
at com.sun.jersey.api.client.Client.init(Client.java:342)
at com.sun.jersey.api.client.Client.access$000(Client.java:118)
at com.sun.jersey.api.client.Client$1.f(Client.java:191)
at com.sun.jersey.api.client.Client$1.f(Client.java:187)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.api.client.Client.<init>(Client.java:187)
at com.sun.jersey.api.client.Client.<init>(Client.java:170)
at com.sun.jersey.api.client.Client.create(Client.java:679)
at com.meritdata.tempo.foundation.security.util.RestfulUtils.request(RestfulUtils.java:33)
at com.meritdata.tempo.foundation.security.util.RestfulUtils.requestGet(RestfulUtils.java:28)
at com.meritdata.tempo.foundation.security.util.PaWebUtils.validatePaToken(PaWebUtils.java:344)
at com.meritdata.tempo.foundation.security.sso.PaSSO.readUserToken(PaSSO.java:137)
at com.meritdata.tempo.foundation.security.filter.UserLoginFilter.validatePortalLogin(UserLoginFilter.java:190)
at com.meritdata.tempo.foundation.security.filter.UserLoginFilter.onAccessDenied(UserLoginFilter.java:248)
at org.apache.shiro.web.filter.AccessControlFilter.onAccessDenied(AccessControlFilter.java:133)
at org.apache.shiro.web.filter.AccessControlFilter.onPreHandle(AccessControlFilter.java:162)
at org.apache.shiro.web.filter.PathMatchingFilter.isFilterChainContinued(PathMatchingFilter.java:203)
at org.apache.shiro.web.filter.PathMatchingFilter.preHandle(PathMatchingFilter.java:178)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:131)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.meritdata.tempo.foundation.security.filter.XssFilter.doFilter(XssFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.meritdata.tempo.foundation.security.filter.CacheControlFilter.doFilter(CacheControlFilter.java:41)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:152)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
- locked <0x0000000612c3a940> (a org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
- <0x000000062d3e9728> (a java.util.concurrent.ThreadPoolExecutor$Worker)


"catalina-exec-998" #1181 daemon prio=5 os_prio=0 tid=0x00007f6b7c359800 nid=0x15c3 waiting for monitor entry [0x00007f6b43cf9000]
java.lang.Thread.State: BLOCKED (on object monitor)
at java.util.zip.ZipFile.getEntry(ZipFile.java:308)
- waiting to lock <**0x000000065888b918**> (a java.util.jar.JarFile)
at java.util.jar.JarFile.getEntry(JarFile.java:240)
at java.util.jar.JarFile.getJarEntry(JarFile.java:223)
at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.getArchiveEntry(AbstractSingleArchiveResourceSet.java:94)
at org.apache.catalina.webresources.AbstractArchiveResourceSet.getResource(AbstractArchiveResourceSet.java:260)
at org.apache.catalina.webresources.StandardRoot.getResourcesInternal(StandardRoot.java:327)
at org.apache.catalina.webresources.CachedResource.validateResources(CachedResource.java:124)
- locked <0x0000000691ae3b90> (a org.apache.catalina.webresources.CachedResource)
at org.apache.catalina.webresources.Cache.getResources(Cache.java:147)
at org.apache.catalina.webresources.StandardRoot.getResources(StandardRoot.java:315)
at org.apache.catalina.webresources.StandardRoot.getClassLoaderResources(StandardRoot.java:231)
at org.apache.catalina.loader.WebappClassLoaderBase.findResources(WebappClassLoaderBase.java:939)
at java.lang.ClassLoader.getResources(ClassLoader.java:1142)
at com.sun.jersey.spi.service.ServiceFinder.getResources(ServiceFinder.java:352)
at com.sun.jersey.spi.service.ServiceFinder.access$200(ServiceFinder.java:159)
at com.sun.jersey.spi.service.ServiceFinder$AbstractLazyIterator.setConfigs(ServiceFinder.java:720)
at com.sun.jersey.spi.service.ServiceFinder$AbstractLazyIterator.hasNext(ServiceFinder.java:732)
at com.sun.jersey.spi.service.ServiceFinder.toClassArray(ServiceFinder.java:595)
at com.sun.jersey.core.spi.component.ProviderServices.getServiceClasses(ProviderServices.java:318)
at com.sun.jersey.core.spi.component.ProviderServices.getServiceClasses(ProviderServices.java:311)
at com.sun.jersey.core.spi.component.ProviderServices.getServices(ProviderServices.java:159)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.initWriters(MessageBodyFactory.java:207)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:163)
at com.sun.jersey.api.client.Client.init(Client.java:342)
at com.sun.jersey.api.client.Client.access$000(Client.java:118)
at com.sun.jersey.api.client.Client$1.f(Client.java:191)
at com.sun.jersey.api.client.Client$1.f(Client.java:187)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.api.client.Client.<init>(Client.java:187)
at com.sun.jersey.api.client.Client.<init>(Client.java:170)
at com.sun.jersey.api.client.Client.create(Client.java:679)
at com.meritdata.tempo.foundation.security.util.RestfulUtils.request(RestfulUtils.java:33)
at com.meritdata.tempo.foundation.security.util.RestfulUtils.requestGet(RestfulUtils.java:28)
at com.meritdata.tempo.foundation.security.util.PaWebUtils.validatePaToken(PaWebUtils.java:344)
at com.meritdata.tempo.foundation.security.filter.UserLoginFilter.keepPaTokenInCookie(UserLoginFilter.java:496)
at com.meritdata.tempo.foundation.security.filter.UserLoginFilter.isAccessAllowed(UserLoginFilter.java:448)
at org.apache.shiro.web.filter.AccessControlFilter.onPreHandle(AccessControlFilter.java:162)
at org.apache.shiro.web.filter.PathMatchingFilter.isFilterChainContinued(PathMatchingFilter.java:203)
at org.apache.shiro.web.filter.PathMatchingFilter.preHandle(PathMatchingFilter.java:178)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:131)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.meritdata.tempo.foundation.security.filter.XssFilter.doFilter(XssFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.meritdata.tempo.foundation.security.filter.CacheControlFilter.doFilter(CacheControlFilter.java:41)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:152)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
- locked <0x0000000612c9dee0> (a org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
- <0x000000062ca8ffc8> (a java.util.concurrent.ThreadPoolExecutor$Worker)

共有1个答案

邓开济
2023-03-14

在您的示例中,catalina-exec-995catalina-exec-998线程竞争同一个对象监视器-地址为0x000000065888B918JARFILE实例。stacktrace已经拥有所有信息。

两个线程都处于blocked状态,而其中一个线程处于等待锁定监视器,另一个线程处于locked监视器。这是绝对正常的情况:获取对象监视器和切换线程状态并不是原子式发生的。

等待进入对象监视器的线程首先获取锁,然后从blocked切换到runnable状态。当您在两者之间进行线程转储时,您可能会准确地捕捉到您所看到的情况。

让我用一个简单的例子来演示这一点。

public class Sync implements Runnable {
    int n;

    public static void main(String[] args) {
        Sync sync = new Sync();
        new Thread(sync, "Sync1").start();
        new Thread(sync, "Sync2").start();
        new Thread(sync, "Sync3").start();
    }

    public void run() {
        for (;;) {
            inc();
        }
    }

    public synchronized void inc() {
        n++;
    }
}

线程转储可能看起来像

"Sync3" #13 prio=5 os_prio=0 tid=0x000000001deab800 nid=0x25d4 runnable [0x000000001e98f000]
   java.lang.Thread.State: RUNNABLE
    at Sync.run(Sync.java:13)
    at java.lang.Thread.run(Thread.java:748)

"Sync2" #12 prio=5 os_prio=0 tid=0x000000001deab000 nid=0x230c waiting for monitor entry [0x000000001e88f000]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at Sync.inc(Sync.java:18)
    - locked <0x000000076b8a1108> (a Sync)
    at Sync.run(Sync.java:13)
    at java.lang.Thread.run(Thread.java:748)

"Sync1" #11 prio=5 os_prio=0 tid=0x000000001deaa000 nid=0x16d4 waiting for monitor entry [0x000000001e78f000]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at Sync.inc(Sync.java:18)
    - waiting to lock <0x000000076b8a1108> (a Sync)
    at Sync.run(Sync.java:13)
    at java.lang.Thread.run(Thread.java:748)

显然,只有一个对象监视器-sync的单个实例。sync1sync2线程都是阻塞的,但其中一个线程是等待锁定,另一个线程已锁定监视器。

 类似资料:
  • 我是Java编程的初学者 物体一次只能移动一个正方形,如果用户想移动到另一个正方形,他们必须再次按键。我的移动方法如下: 我正在使用KeyListener接口来实现keyPressed、keyTyped和KeyRelease方法,我有下面的片段中的条件,在keyPressed内部 这允许对象自由移动。但是,只要按下向上箭头,它显然会继续移动。 有没有办法让物体向上移动一次,比如说-5,然后即使按键

  • 问题内容: 从MDN for NodeList: 在某些情况下,NodeList是一个实时集合,这意味着DOM中的更改会反映在集合中。例如,Node.childNodes处于活动状态: 在其他情况下,NodeList是静态集合,这意味着DOM中的任何后续更改都不会影响集合的内容。document.querySelectorAll返回一个静态NodeList。 所以....有点烦!是否有任何关于哪些

  • 我在JS对象(不是数组)中有一个

  • 我已经建立了一个应用程序,我使用了Okhttp和改装。除了一些不规则的有线行为外,一切正常。在这个新闻应用程序中,我触发了多个部分的提要下载请求。时间到时间请求从不返回任何响应(甚至不会抛出异常),它只是被卡住了,在Logcat中,我看到了连续的垃圾收集。 我试图找到潜在的嫌疑人,但什么都找不到。从ddms中的“线程”中,我唯一能看到的是很多线程都处于“监视”状态(请参见屏幕截图) 编辑:另一个用

  • 我们在Hazelcast客户端中使用ReplicatedMap。客户端和服务器都是版本4.2.1。 地图很小( 我们期望ReplicatedMap.get是非阻塞的,但是在长时间运行的性能测试中,我们开始从vertx(监控阻塞线程)收到如下警告。第一个错误是在6小时后出现的,因此不容易复制。 有没有办法进行非阻塞get?或者我们需要添加EntryListener来维护ConcurrentHashm

  • 当一个线程获得一个对象(比如类B)的监控锁时,它是否获得了属于它的超类(比如类A,其中B扩展了A)的对象的监控锁? 观察 #1 - 当一个线程(通过同步方法拥有派生对象 B 的监视器锁)在超类 A 中调用 wait() 时,第二个线程获取对象 B 的监视器锁并在 A 中进行等待。最后,两个线程同时退出 B 的对象监视器。 我的理解是线程应该在其拥有锁的对象上调用否则这将导致非法监视器状态异常。在