I'm in the process of writing a Rainbow Table generator in Java and the time has come to implement multi-threading to increase the overall speed of the process.
So far, I have a GUI that calls a SwingWorker class that handles the tables construction and population with data.
Within the SwingWorker is a Runnable:
private final Runnable populateTable = new Runnable() { //Generate & write to file};
In order to call populateTable I've implemented an ExecutorService with a FixedThreadPool consisting of four threads to do the generation and writing to disk, the run() method is also synchronised:
ExecutorService executor = Executors.newFixedThreadPool(4);
This is the point at which I become somewhat confused, and show my ignorance when it comes to multi-threading.
Each populateTable run() performs 2000 operations, before finally writing something to a file.
populateTable needs to be run 40,000,000 in order to generate a large enough rainbow table for me to use.
What would be the best (and of course efficient) way of running a 2000 time operation, 40 million times using the four threads?
I hope that makes sense, and any advice or comments would be greatly appreciated.
Thanks
Josh
Executing something on a threadpool 40 million times is unlikely to be efficient. Instead, divide the work into 4 parts and execute 4 runnables that each compute that part and flush the results in appropriate batches.