Swing Worker Threads Not Concurrent

纵然是瞬间 提交于 2019-11-28 01:57:12

The behavior I'm looking for is all 12 threads start working at the same time & finish at the same time.

A CountDownLatch is designed for this very purpose. Here's a good example using a single SwingWorker and a number of subsidiary threads controlled by the latch.

Your question says:

The behavior I'm looking for is all 12 threads start working at the same time & finish at the same time.

But you can't guarantee for all Swing workers threads starting concurrently and ending at same time.

SwingWorker class has a static ExecutorService field with MAX_WORKER_THREADS = 10. I'm not certain why you see 6 and not 10. But you cannot go over 10.

    /**
     * number of worker threads.
     */
    private static final int MAX_WORKER_THREADS = 10;

...

    executorService =
                new ThreadPoolExecutor(1, MAX_WORKER_THREADS,
                                       10L, TimeUnit.MINUTES,
                                       new LinkedBlockingQueue<Runnable>(),
                                       threadFactory);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!