-
Problem with simple Java 2 threads application counting to 1000
Hi,
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
Similar Threads
-
By Dharmesh in forum .NET
Replies: 4
Last Post: 10-01-2001, 03:47 PM
-
Replies: 0
Last Post: 03-21-2001, 04:01 PM
-
By Sam Goldberg in forum Java
Replies: 0
Last Post: 09-26-2000, 09:52 AM
-
By JJ in forum Enterprise
Replies: 1
Last Post: 07-06-2000, 04:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks