由资源稀缺性或者程序自身的问题和缺陷导致线程一直处于非Runnable状态,或者线程虽然处于Runnable状态但是其要执行的任务却一直无法进展的故障现象。
有4种情况
- 死锁
- 锁死
- 饥饿
- 活锁
死锁
如果线程A持有锁L并且想获得锁M,线程B持有锁M并且想获得锁L,那么这两个线程将永远等待下去,这种情况就是最简单的死锁形式。
在数据库系统的设计中考虑了监测死锁以及从死锁中恢复,数据库如果监测到了一组事务发生了死锁时,将选择一个牺牲者并放弃这个事务。Java虚拟机解决死锁问题方面并没有数据库这么强大,当一组Java线程发生死锁时,这两个线程就永远不能再使用了,并且由于两个线程分别持有了两个锁,那么这两段同步代码/代码块也无法再运行了----除非终止并重启应用。
死锁是设计的BUG,问题比较隐晦。不过死锁造成的影响很少会立即显现出来,一个类可能发生死锁,并不意味着每次都会发生死锁,这只是表示有可能。当死锁出现时,往往是在最糟糕的情况----高负载的情况下。
例子
public class DeadLock { private final Object left = new Object(); private final Object right = new Object(); public static void main(String[] args) { DeadLock dl = new DeadLock(); Thread0 t0 = new Thread0(dl); Thread1 t1 = new Thread1(dl); t0.start(); t1.start(); while(true); } public void leftRight() throws Exception { synchronized (left) { Thread.sleep(2000); synchronized (right) { System.out.println("leftRight end!"); } } } public void rightLeft() throws Exception { synchronized (right) { Thread.sleep(2000); synchronized (left) { System.out.println("rightLeft end!"); } } } } class Thread0 extends Thread { private DeadLock dl; public Thread0(DeadLock dl) { this.dl = dl; } public void run() { try { dl.leftRight(); } catch (Exception e) { e.printStackTrace(); } } } class Thread1 extends Thread { private DeadLock dl; public Thread1(DeadLock dl) { this.dl = dl; } public void run() { try { dl.rightLeft(); } catch (Exception e) { e.printStackTrace(); } } }
发现死锁的信息thread dump
2020-03-17 21:53:40 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode): "RMI TCP Connection(2)-169.254.194.204" #17 daemon prio=5 os_prio=0 tid=0x000000001d15b000 nid=0x2d88 runnable [0x000000001f68c000] java.lang.Thread.State: RUNNABLE at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936) at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:327) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1134) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348) at java.util.TreeMap.writeObject(TreeMap.java:2438) at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178) at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1378) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348) at sun.rmi.server.UnicastRef.marshalValue(UnicastRef.java:294) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:334) at sun.rmi.transport.Transport$1.run(Transport.java:200) at sun.rmi.transport.Transport$1.run(Transport.java:197) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$1/256536716.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) 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) Locked ownable synchronizers: - <0x000000076c890250> (a java.util.concurrent.ThreadPoolExecutor$Worker) "JMX server connection timeout 16" #16 daemon prio=5 os_prio=0 tid=0x000000001ea87800 nid=0x3e0c in Object.wait() [0x000000001f41e000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000076cc931c0> (a [I) at com.sun.jmx.remote.internal.ServerCommunicatorAdmin$Timeout.run(ServerCommunicatorAdmin.java:168) - locked <0x000000076cc931c0> (a [I) at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers: - None "RMI Scheduler(0)" #15 daemon prio=5 os_prio=0 tid=0x000000001ea87000 nid=0x4230 waiting on condition [0x000000001f2bf000] java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x000000076c8799c0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers: - None "RMI TCP Connection(1)-169.254.194.204" #14 daemon prio=5 os_prio=0 tid=0x000000001d37e000 nid=0x3554 runnable [0x000000001e91d000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) at java.net.SocketInputStream.read(SocketInputStream.java:170) at java.net.SocketInputStream.read(SocketInputStream.java:141) at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) at java.io.BufferedInputStream.read(BufferedInputStream.java:265) - locked <0x000000076cc5a940> (a java.io.BufferedInputStream) at java.io.FilterInputStream.read(FilterInputStream.java:83) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:550) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$1/256536716.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) 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) Locked ownable synchronizers: - <0x000000076c88d378> (a java.util.concurrent.ThreadPoolExecutor$Worker) "RMI TCP Accept-0" #13 daemon prio=5 os_prio=0 tid=0x000000001d324000 nid=0x2b20 runnable [0x000000001e75f000] java.lang.Thread.State: RUNNABLE at java.net.DualStackPlainSocketImpl.accept0(Native Method) at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131) at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409) at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199) - locked <0x000000076c87c158> (a java.net.SocksSocketImpl) at java.net.ServerSocket.implAccept(ServerSocket.java:545) at java.net.ServerSocket.accept(ServerSocket.java:513) at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:52) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:400) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:372) at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers: - None "Thread-1" #11 prio=5 os_prio=0 tid=0x000000001d0de800 nid=0x1714 waiting for monitor entry [0x000000001df7f000] java.lang.Thread.State: BLOCKED (on object monitor) at io.github.viscent.mtia.ext.DeadLock.rightLeft(DeadLock.java:39) - waiting to lock <0x000000076c4496e0> (a java.lang.Object) - locked <0x000000076c4496f0> (a java.lang.Object) at io.github.viscent.mtia.ext.Thread1.run(DeadLock.java:80) Locked ownable synchronizers: - None "Thread-0" #10 prio=5 os_prio=0 tid=0x000000001d0dd800 nid=0x3b94 waiting for monitor entry [0x000000001ddaf000] java.lang.Thread.State: BLOCKED (on object monitor) at io.github.viscent.mtia.ext.DeadLock.leftRight(DeadLock.java:27) - waiting to lock <0x000000076c4496f0> (a java.lang.Object) - locked <0x000000076c4496e0> (a java.lang.Object) at io.github.viscent.mtia.ext.Thread0.run(DeadLock.java:58) Locked ownable synchronizers: - None "Service Thread" #9 daemon prio=9 os_prio=0 tid=0x000000001d072800 nid=0x1bc8 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "C1 CompilerThread2" #8 daemon prio=9 os_prio=2 tid=0x000000001cfec000 nid=0x35fc runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "C2 CompilerThread1" #7 daemon prio=9 os_prio=2 tid=0x000000001cfe2800 nid=0x3a6c runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "C2 CompilerThread0" #6 daemon prio=9 os_prio=2 tid=0x000000001cfe0800 nid=0x3970 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x000000001cfca800 nid=0x383c waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x000000001bd0e800 nid=0x1560 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "Finalizer" #3 daemon prio=8 os_prio=1 tid=0x000000001bcea000 nid=0x42d0 in Object.wait() [0x000000001cfbf000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000076c388ee0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143) - locked <0x000000076c388ee0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209) Locked ownable synchronizers: - None "Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x000000001bca2800 nid=0xde8 in Object.wait() [0x000000001cc9f000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000076c386b50> (a java.lang.ref.Reference$Lock) at java.lang.Object.wait(Object.java:502) at java.lang.ref.Reference.tryHandlePending(Reference.java:191) - locked <0x000000076c386b50> (a java.lang.ref.Reference$Lock) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153) Locked ownable synchronizers: - None "main" #1 prio=5 os_prio=0 tid=0x0000000002208000 nid=0x15d8 runnable [0x000000000265f000] java.lang.Thread.State: RUNNABLE at io.github.viscent.mtia.ext.DeadLock.main(DeadLock.java:16) Locked ownable synchronizers: - None "VM Thread" os_prio=2 tid=0x000000001bc9b000 nid=0x45a0 runnable "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x000000000221d000 nid=0x2d60 runnable "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x000000000221e800 nid=0x46d8 runnable "GC task thread#2 (ParallelGC)" os_prio=0 tid=0x0000000002220000 nid=0x3a50 runnable "GC task thread#3 (ParallelGC)" os_prio=0 tid=0x0000000002221800 nid=0x3340 runnable "VM Periodic Task Thread" os_prio=2 tid=0x000000001d0b4800 nid=0x4514 waiting on condition JNI global references: 343 Found one Java-level deadlock: ============================= "Thread-1": waiting to lock monitor 0x000000001bca9688 (object 0x000000076c4496e0, a java.lang.Object), which is held by "Thread-0" "Thread-0": waiting to lock monitor 0x000000001bca9528 (object 0x000000076c4496f0, a java.lang.Object), which is held by "Thread-1" Java stack information for the threads listed above: =================================================== "Thread-1": at io.github.viscent.mtia.ext.DeadLock.rightLeft(DeadLock.java:39) - waiting to lock <0x000000076c4496e0> (a java.lang.Object) - locked <0x000000076c4496f0> (a java.lang.Object) at io.github.viscent.mtia.ext.Thread1.run(DeadLock.java:80) "Thread-0": at io.github.viscent.mtia.ext.DeadLock.leftRight(DeadLock.java:27) - waiting to lock <0x000000076c4496f0> (a java.lang.Object) - locked <0x000000076c4496e0> (a java.lang.Object) at io.github.viscent.mtia.ext.Thread0.run(DeadLock.java:58) Found 1 deadlock.
死锁产生的四个必要条件:
1、互斥使用,即当资源被一个线程使用(占有)时,别的线程不能使用
2、不可抢占,资源请求者不能强制从资源占有者手中夺取资源,资源只能由资源占有者主动释放。
3、请求和保持,即当资源请求者在请求其他的资源的同时保持对原有资源的占有。
4、循环等待,即存在一个等待队列:P1占有P2的资源,P2占有P3的资源,P3占有P1的资源。这样就形成了一个等待环路。
破坏其一即可避免,但互斥和不可抢占是天生的多线程特征,只能在后面两个想办法。
避免死锁的方法
- 使用线程协作的帮助类,它们一般是无锁设计,也可以协助锁安全的完成任务,如用Condition 、信号量Semaphore、回环栅栏CyclicBarrier去控制。
- 相比使用Object的wait()、notify(),使用Condition的await()、signal()这种方式实现线程间协作更加安全和高效,显式锁可以借助Condition明确限制争用。
- Semaphore信号量可以控制资源能被多少线程访问,这里我们指定只能被一个线程访问,就做到了类似锁住。而信号量可以指定去获取的超时时间,我们可以根据这个超时时间,去做一个额外处理。对于无法成功获取的情况,一般就是重复尝试,或指定尝试的次数,也可以马上退出。Semaphore其实和锁有点类似,它一般用于控制对某组资源的访问权限。
- CyclicBarrier是统一一组线程,做统一规划,协调线程组步调,比如在run方法的某一点设置一个标记点,指定线程组数量,在一个点中断-续做。
- 粗锁法:使用粗粒度的锁(或者全局同步资源)代替多个锁(破坏占用并等待资源)。缺点:降低了并发性并可能导致资源浪费
- 锁排序法:相关线程使用全局统一的顺序申请锁(破坏 循环等待资源)
- 使用ReentrantLock.tryLock(long,TimeUnit)申请锁,指定了一个超时时间,在时间内锁申请成功则返回true,超时则返回false
- 避免嵌套锁:这是死锁的主要原因。死锁主要发生在我们给多个线程加锁的时候。如果我们已经给了一个线程,就不要给多个线程加锁。
- 避免不必要的锁:我们应该只锁那些需要的成员。不必要地打开锁会导致死锁。
- 使用线程join:join()的作用是:“等待该线程终止”,这比较低效。
锁死Lockout
1、信号丢失锁死
由于没有相应的通知线程来唤醒等待线程而使等待线程一直处于等待状态的一种活性故障
2、嵌套监视器锁死
嵌套锁导致等待线程永远无法被唤醒的一种活性故障
线程饥饿
线程一直无法获得其所需的资源而导致其任务一直无法进展的一种活性故障。
活锁
活锁是另一种形式的活跃性问题。该问题尽管不会阻塞线程,但也不能继续执行,因为线程将不断重复同样的操作,而且总会失败。活锁通常发生在处理事务消息中:如果不能成功处理某个消息,那么消息处理机制将回滚事务,并将它重新放到队列的开头。这样,错误的事务被一直回滚重复执行。这种形式的活锁通常是由过度的错误恢复代码造成的,因为它错误地将不可修复的错误认为是可修复的错误。
当多个相互协作的线程都对彼此进行相应而修改自己的状态,并使得任何一个线程都无法继续执行时,就导致了活锁。这就像两个过于礼貌的人在路上相遇:他们彼此让路,然后在另一条路上相遇,然后他们就一直这样避让下去。
要解决这种活锁问题,需要在重试机制中引入随机性。例如在网络上发送数据包,如果检测到冲突,都要停止并在一段时间后重发。如果都在1秒后重发,还是会冲突。所以引入随机性可以解决该类问题。
重点在于不断地循环。
例子:一个罪犯绑架了一名人质,他要求赎金以释放人质。一旦人质获释,警方同意给罪犯他想要的钱。罪犯只有拿到钱才释放人质。两人都在等待对方先行动。
public class Criminal { private boolean hostageReleased = false; public void releaseHostage(Police police) { while (!police.isMoneySent()) { System.out.println("Criminal: waiting police to give ransom"); try { Thread.sleep(1000); } catch (InterruptedException ex) { ex.printStackTrace(); } } System.out.println("Criminal: released hostage"); this.hostageReleased = true; } public boolean isHostageReleased() { return this.hostageReleased; } } public class Police { private boolean moneySent = false; public void giveRansom(Criminal criminal) { while (!criminal.isHostageReleased()) { System.out.println("Police: waiting criminal to release hostage"); try { Thread.sleep(1000); } catch (InterruptedException ex) { ex.printStackTrace(); } } System.out.println("Police: sent money"); this.moneySent = true; } public boolean isMoneySent() { return this.moneySent; } } public class HostageRescueLivelock { static final Police police = new Police(); static final Criminal criminal = new Criminal(); public static void main(String[] args) { Thread t1 = new Thread(new Runnable() { public void run() { police.giveRansom(criminal); } }); t1.start(); Thread t2 = new Thread(new Runnable() { public void run() { criminal.releaseHostage(police); } }); t2.start(); } }
我们可以看到,这2个线程一直在waiting
2020-03-18 08:55:54 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode): "RMI TCP Connection(2)-169.254.194.204" #18 daemon prio=5 os_prio=0 tid=0x000000001e669800 nid=0x35d4 runnable [0x000000001f02e000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) at java.net.SocketInputStream.read(SocketInputStream.java:170) at java.net.SocketInputStream.read(SocketInputStream.java:141) at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) at java.io.BufferedInputStream.read(BufferedInputStream.java:265) - locked <0x000000076d524388> (a java.io.BufferedInputStream) at java.io.FilterInputStream.read(FilterInputStream.java:83) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:550) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$1/861125748.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) 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) Locked ownable synchronizers: - <0x000000076cc57ec0> (a java.util.concurrent.ThreadPoolExecutor$Worker) "JMX server connection timeout 17" #17 daemon prio=5 os_prio=0 tid=0x000000001e6a6000 nid=0x398c in Object.wait() [0x000000001f1cf000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000076d05ae20> (a [I) at com.sun.jmx.remote.internal.ServerCommunicatorAdmin$Timeout.run(ServerCommunicatorAdmin.java:168) - locked <0x000000076d05ae20> (a [I) at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers: - None "RMI Scheduler(0)" #16 daemon prio=5 os_prio=0 tid=0x000000001e6a5800 nid=0x2a30 waiting on condition [0x000000001ef0f000] java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x000000076cc41c40> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers: - None "RMI TCP Connection(1)-169.254.194.204" #15 daemon prio=5 os_prio=0 tid=0x000000001d3bf000 nid=0x2cf8 runnable [0x000000001e5ad000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) at java.net.SocketInputStream.read(SocketInputStream.java:170) at java.net.SocketInputStream.read(SocketInputStream.java:141) at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) at java.io.BufferedInputStream.read(BufferedInputStream.java:265) - locked <0x000000076d0228c0> (a java.io.BufferedInputStream) at java.io.FilterInputStream.read(FilterInputStream.java:83) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:550) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$1/861125748.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) 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) Locked ownable synchronizers: - <0x000000076cc54fe8> (a java.util.concurrent.ThreadPoolExecutor$Worker) "RMI TCP Accept-0" #14 daemon prio=5 os_prio=0 tid=0x000000001d33a000 nid=0x323c runnable [0x000000001dd3e000] java.lang.Thread.State: RUNNABLE at java.net.DualStackPlainSocketImpl.accept0(Native Method) at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131) at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409) at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199) - locked <0x000000076cc443d8> (a java.net.SocksSocketImpl) at java.net.ServerSocket.implAccept(ServerSocket.java:545) at java.net.ServerSocket.accept(ServerSocket.java:513) at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:52) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:400) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:372) at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers: - None "DestroyJavaVM" #12 prio=5 os_prio=0 tid=0x0000000002388000 nid=0x12d0 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "Thread-1" #11 prio=5 os_prio=0 tid=0x000000001d0ed000 nid=0x3980 waiting on condition [0x000000001e0ae000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at io.github.viscent.mtia.ext.livelock.Criminal.releaseHostage(Criminal.java:12) at io.github.viscent.mtia.ext.livelock.HostageRescueLivelock$2.run(HostageRescueLivelock.java:20) at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers: - None "Thread-0" #10 prio=5 os_prio=0 tid=0x000000001d0ec000 nid=0x3bac waiting on condition [0x000000001de4f000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at io.github.viscent.mtia.ext.livelock.Police.giveRansom(Police.java:13) at io.github.viscent.mtia.ext.livelock.HostageRescueLivelock$1.run(HostageRescueLivelock.java:13) at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers: - None "Service Thread" #9 daemon prio=9 os_prio=0 tid=0x000000001d0ba000 nid=0x4064 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "C1 CompilerThread2" #8 daemon prio=9 os_prio=2 tid=0x000000001d034000 nid=0x10ec waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "C2 CompilerThread1" #7 daemon prio=9 os_prio=2 tid=0x000000001d032000 nid=0x3ecc waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "C2 CompilerThread0" #6 daemon prio=9 os_prio=2 tid=0x000000001bbdf000 nid=0x2d60 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x000000001bbdc000 nid=0x1938 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x000000001d00b800 nid=0x3380 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "Finalizer" #3 daemon prio=8 os_prio=1 tid=0x000000001bbba000 nid=0x4444 in Object.wait() [0x000000001cfff000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000076c388ee0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143) - locked <0x000000076c388ee0> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209) Locked ownable synchronizers: - None "Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x000000001bb72800 nid=0x2098 in Object.wait() [0x000000001cc6f000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000076c386b50> (a java.lang.ref.Reference$Lock) at java.lang.Object.wait(Object.java:502) at java.lang.ref.Reference.tryHandlePending(Reference.java:191) - locked <0x000000076c386b50> (a java.lang.ref.Reference$Lock) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153) Locked ownable synchronizers: - None "VM Thread" os_prio=2 tid=0x000000001bb6b000 nid=0x24bc runnable "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x000000000239d000 nid=0x1eb8 runnable "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x000000000239e800 nid=0x2a50 runnable "GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00000000023a0000 nid=0x3c8c runnable "GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00000000023a1800 nid=0x27b8 runnable "VM Periodic Task Thread" os_prio=2 tid=0x000000001d0bb800 nid=0x1410 waiting on condition JNI global references: 342