• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About suspend() and resume() in Thread

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,
A new comer to this forum.Got the following doubt.
Which one statement below is true concerning the following application?
1. class TestThread2 extends Thread {
2. public void run() {
3. System.out.println("Starting");
4. yield();
5. resume();
6. System.out.println("Done");
7. }
8.
9. public static void main(String args[]) {
10. TestThread2 tt = new TestThread2();
11. tt.start();
12. }
13. }
I found this question in a mock test exam.I don't remember the name of this exam.
The answer given is both the "Starting" and "Done" will be printed.
But i think that only "Starting" will be printed because after the thread tt is suspended the resume will have no effect and it will remain in the hanging position until you stop the application by pressing ^C.
Pls clear my doubt.Thanking all of you in advance.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i got your doubt,
yield() is a static method of thead class.when ever yield() is called ,thread changes its state from running to ready. when thread was scheduled again by CPU it will change its state to running .
yield()
RUNNING----------->READY
READY ------------>RUNNING
****************************************************
suspend() is instance method of thread class,it has no control on its own ,but some other thread has to call resume method on this thread.until some thread is not called it will be in blocked state.when ever resume() ic called it will change its state to ready state.
suspend()
RUNNING STATE----------------->(SUSPENDED)BLOCKED state

resume()
(SUSPENDED)BLOCKED STATE---------------->READY STATE

READY---------->RUNNING
when ever thread was allowed by CPU ,it will change from ready to running state
hope this clears you
suresh
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same problem two weeks ago.
Lets talk a Walk thru the code.
1. starting with the run() method
2. the System class used system.out to print "Starting"
3. the Thread class static method yield() move the thread from a running state to a ready state. When the JVM determine that there are resources available to run the thread in question. the JVM on it own, will start running the thread.
4. the depreciated Thread class method resume() does nothing.
5. the System class used system.out to print "Done"
6. the run() method ends
hope this helps, Monty6
[This message has been edited by monty6 (edited June 22, 2000).]
 
debasish tripathy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx a lot for your kind help.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic