How to manage default SwingWorker Java thread pool?

I have an application that uses 2 lengthy SwingWorker tasks, and I just came across several Windows computers with updated JVMs that only start one of them. There are no errors, so I should assume that the default thread pool has only one thread, so the second SwingWorker object is queued when I try to execute it.

So, (1) how to check how many threads are available in the SwingWorker default thread pool, and (2) how to add threads if I need more?

Anything else I should know? This seemingly single-threaded thread pool situation contradicts all my expectations.

I am creating a ThreadPoolExecutor, but this seems so wrong ...

+3
source share
3 answers

Maybe a little late, but there is a bug in newer versions of Java: SwingWorker deadlocks due to one thread in the swingworker pool

+2
source

The SwingWorker thread pool has 10 threads by default (defined in the SwingWorker.MAX_WORKER_THREADS private variable). If you see only one of your tasks, I would check the status of another thread using JConsole or another similar tool.

There is no easy way to link the default SwingWorker thread pool (it is private and does not undergo any public methods). Adding SwingWorkers to your own thread pool is the expected way to handle it if the default pool does not work.

+1

JDK 6 10.

Usually you do not need to create a ThreadPoolExecutor, usually the default thread pool used by the swing worker is used. Creating a ThreadPoolExecutor can be awkward, as some of the static methods create a pool with only one thread.

You might want to add logs to these threads, if they are not already present, and check the logs. Perhaps another synchronization issue is stopping the second background task.

0
source

Source: https://habr.com/ru/post/1743859/


All Articles