Chris Hurst wrote:Your last thread is very inefficient ...
Think about what this is doing it attempting to murder the CPU checking why the threads haven't finished (they are being delayed by this thread burning lots of CPU unless you have enough cores), its like a nagging child in a car saying are we there yet i.e. putting a sleep or yield in the loop would help though better solutions exist i.e. really this thread should be waiting for a signal/ joining whatever.
Have a look at Java 7's fork / join for instance ...
Vijitha Kumara wrote:Welcome to CodeRanch, Rony Dsouza!
I would like to know if there is a way where in i could write the result to file when both the threads finished their work?
Also the main method/thread finshes before the other threads are done processing can I make the main thread wait till other threads finish execution?
You have to make the main thread waiting for those two threads... Then you can continue the main thread. There can be few options on how to implement this. Can you show us how you have implemented it so far?