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(); } }

转载于:https://www.cnblogs.com/zhjh256/p/6477220.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值