Results 1 to 1 of 1
- 01-02-2010, 03:16 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 76
- Rep Power
- 0
How can a thread disorder in other thread work?
Hello
sleep() in Thread may throw an InterruptedException.If some Threads want
to disorder in Defered thread,this state occured.
For example how "main thread" can() in work of "CounterThread"?
Java Code:import java.lang.Runnable; class Counter implements Runnable { public int count = 1; Thread t; Counter() { t=new Thread(this,"CounterThread"); t.start(); } public void run() { while (count < 3) { try { System.out.println(count); Thread.sleep(4000); } catch (InterruptedException e) { System.out.println("InterruptedException"); } count++; } System.out.println("+"); } } public class B { public static void main(String args[]) throws Exception { Counter r = new Counter(); for(int i=0;i<5;i++) { Thread.sleep(1000); System.out.println("i= "+i); } } }
Similar Threads
-
Difference between Thread.yield() and Thread.sleep() methods
By Nageswara Rao Mothukuri in forum New To JavaReplies: 12Last Post: 07-30-2010, 05:37 PM -
Retry constructing a thread/ terminate thread
By coyote1982 in forum New To JavaReplies: 6Last Post: 09-17-2009, 09:38 AM -
[SOLVED] Method from one thread called on another thread
By Ypsilon IV in forum Threads and SynchronizationReplies: 7Last Post: 04-24-2009, 02:07 PM -
If JNI thread call the java object in another thread, it will crash.
By skaterxu in forum Advanced JavaReplies: 0Last Post: 01-28-2008, 07:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks