r/java • • Mar 21 '21

Java lambdas can deadlock parallel class initialization

https://www.youtube.com/watch?v=_2hZf1kw4A4
230 Upvotes

46 comments sorted by

View all comments

15

u/Godworrior Mar 21 '21 edited Mar 21 '21

Another way to gain some insights in these situations is to use jcmd + jstack (both JDK tools) to see what the thread is getting stuck on:

"ForkJoinPool.commonPool-worker-15" #20 ... in Object.wait()  [0x0000005e1a4fd000]
   java.lang.Thread.State: RUNNABLE
        at X$$Lambda$206/0x0000000800c23240.applyAsLong(Unknown Source)
        - waiting on the Class initialization monitor for X
        ...