Results 1 to 5 of 5
Thread: Serial Execution of threads
- 11-09-2010, 12:40 PM #1
Member
- Join Date
- Mar 2008
- Posts
- 1
- Rep Power
- 0
- 11-09-2010, 01:06 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Multiple thread not guaranteed by the thread pool that it'll executed in same order that you start.
- 11-09-2010, 02:11 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
- 11-09-2010, 05:07 PM #4
Maybe this helps:
Java Code:public class threadClass { int i=1; public threadClass() { Thread t1 = new Thread(run1); Thread t2 = new Thread(run2); Thread t3 = new Thread(run3); t1.start(); t2.start(); t3.start(); } Runnable run1 = new Runnable(){ public void run() { while(true) { if((i%3)==0){ System.out.println("thread 1: " + i++); } } } }; Runnable run2 = new Runnable(){ public void run() { while(true) { if((i%3)==1){ System.out.println("thread 2: " + i++); } } } }; Runnable run3 = new Runnable(){ public void run() { while(true) { if((i%3)==2){ System.out.println("thread 3: " + i++); } } } }; public static void main(String... args) { new threadClass(); } }
- 11-09-2010, 05:37 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Still the same, run your code for a long time. You can see the values a messup.
Similar Threads
-
serial communication is very slow while reading from serial port
By elsanthosh in forum AWT / SwingReplies: 1Last Post: 07-30-2010, 08:29 AM -
JAR execution
By patoh in forum New To JavaReplies: 2Last Post: 11-26-2008, 09:09 AM -
execution of threads
By jyotigupta6 in forum Threads and SynchronizationReplies: 5Last Post: 11-16-2008, 12:28 AM -
Threads execution stop
By jyotigupta6 in forum Threads and SynchronizationReplies: 1Last Post: 10-31-2008, 01:41 PM -
slow execution and flickery graphics. too many threads?
By lost_in_java in forum Threads and SynchronizationReplies: 0Last Post: 01-23-2008, 02:26 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks