Implementing Java StatusStreadPool
This is about an application that needs to handle (VAD, Loudness, Clipping) a lot of sound files (like 100k). At this time, I create as many callables as I can fit into memory, and then start everything with threadPool.invokeAll (), write the results to the file system, unload the processed files and continue in step 1. Due to the fact that GUI application, I don't want the user to feel like the application is "unresponsive" when processing all sound files. (which it calls invokeAll at this time, blocks). I'm not sure what a "good" way to fix this is. The user shouldn't have to do other things during processing, but I would like to show a progress bar like "10 out of 100,000 sound files". So how do I get there? Should I create "observer thread "so that each worker does a callback? I'm new to multithreading and don't understand the idea behind such a mechanism.
If you need to know: I am using SWT / JFace.
a source to share
You can use ExecutorCompletionService
for this purpose; if you submit each of the tasks Callable
in a loop, you can call the take
completion service method - receive jobs one at a time upon completion. Every time you complete a task, you can update your GUI.
Alternatively, you can implement your own ExecutorService
, which is also Observable
one that allows updates to be published to the subscription Observer
when the task is completed.
a source to share
You should take a look SwingWorker
. It is a good class for doing lengthy operations, reporting progress in the gui and maintaining a responsive gui.
Using the Swing Worker thread contains some useful information.
a source to share