可以运行的Swing工作线程的最大数量是多少 [英] Whats the maximum number of swing worker threads that can be run

查看:95
本文介绍了可以运行的Swing工作线程的最大数量是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以运行的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆