Skip to main content

Thread: Threads suspention


hi, how suspend 1 thread other it's work if 2 threads (t1 & t2)t1 lower priority thread , t2 higher priority thread in java. t1 prints "hello" inside loop 5 time after sleeping 3 secs while t2 prints "world" once after 7 secs.
e.g

code:
for(int i=0; i<4; i++){       thread t1 = new thread();       t1.sleep(3000);       system.out.print("hello");  }
t2 supposed interrupt t1 after 7 sec print "world"

quote posted jmwalloh view post
hi, how suspend 1 thread other it's work if 2 threads (t1 & t2)t1 lower priority thread , t2 higher priority thread in java. t1 prints "hello" inside loop 5 time after sleeping 3 secs while t2 prints "world" once after 7 secs.
e.g

code:
for(int i=0; i<4; i++){      thread t1 = new thread();      t1.sleep(3000);      system.out.print("hello"); }
t2 supposed interrupt t1 after 7 sec print "world"
your code has no meaning. thread t1 never started... thread.sleep() static method, ie, if code in thread calls it, thread goes sleep. if ever implement correctly, ie, start 2 threads, , code 1 thread sleeps 3 secs , prints "hello" 5 times, while code of other sleeps 7s before printing "word", first thread ended before second wakes up, whatever priorities assign them.


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Threads suspention


Ubuntu

Comments

Popular posts from this blog

Falang and too many redirects - Joomla! Forum - community, help and support

Infinite loop detected in JErrorInfinite loop detected in JError - Joomla! Forum - community, help and support

logged out from joomla! - Joomla! Forum - community, help and support