可以运行的Swing工作线程的最大数量是多少 [英] Whats the maximum number of swing worker threads that can be run
问题描述
可以运行的Swing Worker线程数是否有上限?或者就内存支持而言,这是上限吗?在某个地方也可以配置吗?
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?
推荐答案
SwingWorker
本身不是线程,而是将在线程中执行的任务.通常,您将使用ExecutorService
执行SwingWorker
的实例.此接口还允许设置线程数:
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);
现在,如果您提交了n个以上的SwingWorker
实例,它们将不得不排队等待,直到池中的线程可用为止.
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.
这篇关于可以运行的Swing工作线程的最大数量是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!