<AWT Dev> deadlock between AppKit main thread and AWT event thread in JDK 17

Alan Snyder javalists at cbfiddle.com
Mon Jun 28 14:30:01 UTC 2021


My code (#2) running on the AWT thread is blocked trying to perform selector on main thread waiting YES. It is blocked because it does not specify that it can be run under the javaRunLoopMode. It specifies the AWTRunLoopMode, which is the old name. That name is supplied by JavaNativeFoundation.

The main thread is blocked waiting for an upcall to Java to get accessibility information, which is blocked waiting for code to run on the AWT thread.

Neither thread can proceed until the other one completes its operation. Hence, a deadlock.

In both cases, “blocked” is a soft block, because both threads are running a nested run loop, but the conditions for exiting those run loops are not met.

The run loop name used by AWT needs to be part of the public API of the JDK.



> On Jun 28, 2021, at 7:16 AM, Michael Hall <mik3hall at gmail.com> wrote:
> 
> 
> 
>> On Jun 28, 2021, at 9:03 AM, Alan Snyder <javalists at cbfiddle.com> wrote:
>> 
>> You can call performSelectorOnMainThread directly, but you have to know the name of the AWT/Java run loop to avoid the deadlock situations that I have encountered.
>> 
>> The name of the run loop needs to be part of the public API.
> 
> I haven’t successfully done much with the native run loop. I didn’t quite follow your deadlock either. What was it blocked on? It almost sounded like three starvation where the thread just never got run for some reason. Or you aren’t sure what the deadlock is on? I did get into deadlocks trying to do a OS X native watch service  using kqueue that I never figured out.  
> Which public API? JavaNativeFoundation?
> 
>> 
>> By the way, upcalls from AppKit to get accessibility information has been a source of problems for a long time. I don’t suppose there is any way that Java can respond to these requests without running code on the AWT event thread?
> 
> Again native I have done hasn’t involved anything to do with AppKit so I’m not sure what you’re looking for here either. 



More information about the awt-dev mailing list