File IO and the Swing Event Dispatch Thread
Alan Bateman
Alan.Bateman at oracle.com
Tue Dec 1 13:14:45 UTC 2020
On 01/12/2020 12:59, Dávid Karnok wrote:
> Hello.
>
> I watched the recent interview ( https://www.youtube.com/watch?v=EDVesJ-yJ6U
> ) considered the following scenario: in a Swing desktop app, the user
> clicks a button which then reads through a file, right there in the
> ActionListener.
>
> If I understood the interview correctly, the Event Dispatch Thread won't be
> supporting suspensions so one has to make a custom scheduler that delegates
> back to it, right? Second, I presume async file IO needs OS support (
> https://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part1.html ) thus
> could/would it work on, let's say Windows, without ending up with arbitrary
> number of blocked OS threads?
There is work-in-progress that is investigating if it makes sense to use
the AWT Event Dispatch Thread (EDT) or the Java FX application thread as
a carrier thread. You can of course create a custom scheduler today with
`Executor scheduler = EventQueue::invokeLater` but each of the virtual
threads will have its own identity. Part of the investigation is to see
is to see if methods such as isDispatchThread should return true when
the carrier thread is the EDT. It may be the conclusion is that it's not
worth doing but if you have experience in this area then please share it.
The current support for custom schedulers doesn't have the equivalent of
ManagedBlocker, which I think is what you are asking. When using the
default scheduler then the set of carrier threads may temporarily expand
for these cases.
-Alan
More information about the loom-dev
mailing list