Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the maximum number of swing worker threads that can be run

Is there an upper limit on the number of Swing Worker threads that can be run or is it like as far as the memory supports? Also is this configurable somewhere?

like image 577
Sreenath Prem Avatar asked Dec 02 '11 13:12

Sreenath Prem


1 Answers

A SwingWorker is not a thread itself but a task that will be executed in a thread. Usually, you would use an ExecutorService to execute instances of SwingWorker; this interface also allows to set the number of threads:

 int n = 20; // Maximum number of threads
 ExecutorService threadPool = Executors.newFixedThreadPool(n);
 SwingWorker w; //don't forget to initialize
 threadPool.submit(w);

Now, if you submit more than n SwingWorker instances, they'll have to queue up and wait until a thread from the pool gets available.

like image 58
mort Avatar answered Sep 22 '22 02:09

mort