可以运行的最大 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SwingWorker
本身不是线程,而是将在线程中执行的任务。通常,您会使用 ExecutorService 来执行 SwingWorker 的实例;该接口还允许设置线程数:现在,如果您提交超过 n 个
SwingWorker
实例,它们将必须排队并等待,直到池中的线程可用。A
SwingWorker
is not a thread itself but a task that will be executed in a thread. Usually, you would use anExecutorService
to execute instances ofSwingWorker
; this interface also allows to set the number of threads: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.上面的代码示例将允许您执行超过默认数量的 SwingWorkers。当然,它正在访问一些后门 sun.awt.AppContext 类,但对于那些感兴趣但无法/不愿意提供自己的 ExecutorService 的人来说,这是一个快速解决方法。
The above code sample will allow you to have more than the default number of SwingWorkers executing. Of course it is accessing some backdoor sun.awt.AppContext class, but it is a quick workaround for those interested, and not able/willing to provide their own ExecutorService.