I have been trying to write some java application. What this application wants to run is processing a text file.
However, that input text file is large, (over 200mb) I t
You need to start a thread. So:
new Thread(worker1).start();
new Thread(worker2).start();
new Thread(worker3).start();
new Thread(worker4).start();
Reading files on one disk usually does not benefit from multithreading.
Try to improve the way you read and process the file. Use a BufferedReader if you do not already use a buffer.
If you do a lot of processing from what is read, then consider multithreading the processing while keeping one thread dedicating to reading.
To run concurrent tasks, you should use an ExecutorService that you instanciate thanks to Executors. Take some time to read the javadoc.
worker1.run();
calls your run method directly. To start a thread (which calls your run method in the new thread), use:
worker1.start();
(similar for worker2/3/4)
Edit: I thought the workers were Threads, not Runnables. mvieghofer's answer is correct.
Runnable object is not Thread, you need use Thread to run the Runnable Object, like this:
new Thread(worker1).start();
but i think you may face other problems, so please read the java document.