Problem with simple Java 2 threads application counting to 1000
As fa as i'm concerned this is a thread licecycle:
1. thread created: it is dead.
2. thread started: it is now alive.
3. thread executes its run method: it is alive during this method.
4. after thread finishes its run method: it is dead.
No I have simple JUnit code:
public void testThreads() throws Exception {
WorkTest work = new WorkTest() {
public void release() {
// TODO Auto-generated method stub
}
public void run() {
for (int i=0;i<1000;i++){
log.debug(i+":11111111111");
//System.out.println(i+":11111111111");
}
}};
WorkTest work2 = new WorkTest() {
public void release() {
// TODO Auto-generated method stub
}
public void run() {
for (int i=0;i<1000;i++){
log.debug(i+":22222222222");
}
}};
Thread workerThread = new Thread(work);
Thread workerThread2 = new Thread(work2);
workerThread.start();
//workerThread.join();
workerThread2.start();
//workerThread2.join();
}
And
public interface WorkTest extends Runnable {
public abstract void release();
}
And that's it..
On the console I see 999 iterations of both threads only if i uncomment
//workerThread.join();
//workerThread2.join();
In other case I see random number of iterations - JUNIT finishes and Thread1 made 54 and Thread2 233 iterations - the numbers are different every time i start the JUnit..
What I want? Not to wait until the first one finishes - I want them to start at the same time and they must FINISH their tasks...
Please help me asap :(

