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. The tasks are quite short, but there is a lot of them which is why I used an 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. 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. 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?
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
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
.