[英]ExecutorService JProgressBar
This is probably a simple one, but I've tried loads of different things and no matter what I try, I can't get this to work. 这可能很简单,但是我尝试了很多不同的事情,无论我尝试什么,我都无法正常工作。
Basically I have a JProgressBar that I want to update as I process the task list. 基本上,我有一个要在处理任务列表时更新的JProgressBar。 The tasks are quite short, but there is a lot of them which is why I used an ExecutorService.
任务很短,但是任务很多,这就是为什么我使用ExecutorService的原因。
The problem is that I can't find a good way to listen to the ExecutorService for how many tasks are left to process. 问题是我找不到监听ExecutorService剩下要处理的任务的好方法。 invokeAll() blocks until all the tasks are complete an if I use submit() to execute each task, the tasks are pretty much done by the time it hits the code for the JProgressBar.
invokeAll()阻塞直到所有任务完成为止,如果我使用Submit()执行每个任务,则在命中JProgressBar的代码时,这些任务已基本完成。 I even tried interleaving the two but that was just nasty.
我什至尝试将两者交错,但这太讨厌了。
Is there an easy way to submit a batch of tasks (implementing callable), then call an execute() method which starts processing in? 有没有简单的方法来提交一批任务(实现可调用),然后调用execute()方法开始处理?
Or am I looking in completely the wrong direction here? 还是我在寻找完全错误的方向?
Thanks! 谢谢!
You could use an ExecutorCompletionService
: http://download.oracle.com/javase/1,5.0/docs/api/java/util/concurrent/ExecutorCompletionService.html 您可以使用
ExecutorCompletionService
: http : //download.oracle.com/javase/1,5.0/docs/api/java/util/concurrent/ExecutorCompletionService.html
The examples on the doc page are pretty good ;) 文档页面上的示例非常好;)
Basically you're just submitting the tasks to the service and then poll or take. 基本上,您只是将任务提交给服务,然后进行轮询或执行。 After a task got back, you can update your
JProgressbar
. 任务返回后,您可以更新
JProgressbar
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.