zoukankan      html  css  js  c++  java
  • ReentrantLock$Sync.tryRelease java.lang.IllegalMonitorStateException

    早上一来,例行性的看主要环境的运行情况,发现有个环境中有如下异常:

    17-02-28 08:13:37.368 ERROR pool-2-thread-65 com.ld.net.spider.SpiderClient.call(SpiderClient.java:75):
    java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.ld.net.spider.SpiderClient.call(SpiderClient.java:65)
    at com.ld.net.remoting.rmq.LDSpiderMultiServiceBeanConfigurer$DealRequest.handleCall(LDSpiderMultiServiceBeanConfigurer.java:677)
    at com.ld.net.remoting.rmq.LDSpiderMultiServiceBeanConfigurer$DealRequest.processRequest(LDSpiderMultiServiceBeanConfigurer.java:604)
    at com.ld.net.remoting.rmq.LDSpiderMultiServiceBeanConfigurer$2$1.run(LDSpiderMultiServiceBeanConfigurer.java:222)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.IllegalMonitorStateException
    at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:151)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1261)
    at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:457)
    at com.ld.net.spider.stat.ServiceStatHelper.writeSlowRequest(ServiceStatHelper.java:80)
    at com.ld.net.spider.SpiderRouter.call(SpiderRouter.java:116)
    at com.ld.net.spider.SpiderRouter.call(SpiderRouter.java:63)
    at com.ld.net.spider.client.RpcServiceProxyImpl.callService(RpcServiceProxyImpl.java:292)
    at com.ld.net.spider.client.RpcServiceProxyImpl.invoke(RpcServiceProxyImpl.java:246)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
    at com.sun.proxy.$Proxy28.funcl_trd_offer_QuerySecuCancel(Unknown Source)

    直接找到对应的源码看了下逻辑,同时网上搜了下,又仔细看了下代码和javadoc,报错的代码如下:

            try {
                if (lock.tryLock() || lock.tryLock(1, TimeUnit.MICROSECONDS)) {
                    // 此处为业务逻辑...
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }

    javadoc中关于lock.unlock的说明如下:

    没有注意到释放未持有的锁会导致该异常,更改为如下,问题即可解决。

            try {
                if (lock.tryLock() || lock.tryLock(1, TimeUnit.MICROSECONDS)) {
                    // 此处为业务逻辑...
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                if (lock.isHeldByCurrentThread()) {
                    lock.unlock();
                }
            }
  • 相关阅读:
    shell脚本,批量创建10个系统帐号并设置密码为随机8位字符串。
    shell脚本,在指定目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件。
    shell脚本,按字母出现频率降序排序。
    django 上传图片、使用PIL制作缩略图并保存到sea的storage
    mongo数据库基本操作--python篇
    看懂sh脚本
    推荐系统实践--基于用户的协同过滤算法
    推荐系统实践--概述
    django “如何”系列10:如何管理静态文件
    django “如何”系列9:三合一:利用遗留的数据库、输出csv和输出pdf
  • 原文地址:https://www.cnblogs.com/zhjh256/p/6477220.html
Copyright © 2011-2022 走看看