Virtual Threads - deadlock with synchronized (Main.class) and System.out.println

Dr Heinz M. Kabutz heinz at javaspecialists.eu
Tue Jul 18 20:47:53 UTC 2023


On 2023/07/18 10:46, Alan Bateman wrote:
> On 18/07/2023 07:29, Dr Heinz M. Kabutz wrote:
>> Hi Ron,
>>
>> should this also be emitted with the -Djdk.tracePinnedThreads=full 
>> event? It doesn't seem to be at the moment.
>
> There's a lot of puzzler material here. That system property prints a 
> stack trace to System.out so it might, or might not, block trying to 
> acquire the lock for System.out. Before you ask, the reason you might 
> not see a JFR event is because that event is committed after the 
> pinned thread continues (so it can include the duration). In the 
> deadlock scenario, the thread that is pinned due to synchronized 
> (Main.class) { ... } is not chosen as the waiter to release, so it 
> parks indefinitely.
>
> -Alan

Oh my, that is so nasty!

Thus we can make the problem vanish with System.setOut(new 
PrintStream(System.out) {});

:-)

Heinz



More information about the loom-dev mailing list