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
t2 supposed interrupt t1 after 7 sec print "world"code:for(int i=0; i<4; i++){ thread t1 = new thread(); t1.sleep(3000); system.out.print("hello"); }
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
Post a Comment