• 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

when will a thread stop

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am posting this again
2. Under which circumstances will a thread stop
A. the method waitforId() in class mediaTracker is called
B. the run() method that the thread is executing ends
C. The call to the start() method of the Thread object returns
D. The suspend() method is called on the Thread object
E. The wait method is called on the Thread object
My understanding
A) I tried to track down the waitForId() method, which calls some other methods, which call some method of the toolkit class,
which are supposed to load the image. So untill the Image is loded the thread waits. If the thread is waiting, then it is not running so it has stopped (running).True.
B)The run method execution ends. The thread stops executing because there is nothing to execute, so it stops ( running).True
C) The start() method doesnt wait for the run method of the new thread to finish execution. start() method returns even if the thread of execution started by it is still executing.False.
D)Suspend Method is called on the new Object.(Do we need to know this for the exam?).By definition suspend Method will stop the thread untill it is resumed. True.
E)Wait method will also stop the thread from running, Untill it is notified by some other thread.True
My choices are not accepted by the Mughal Test.(It says only b is correct).
I am sure this question has been discussed before, but I still havent come across a definitive answer. Kindly tell me link to some previous discussion of this question.

[This message has been edited by mohit joshi (edited October 06, 2000).]
[This message has been edited by mohit joshi (edited October 07, 2000).]
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why don't you search for this topic in this forum.
There has already been lots of discussion on this topic. PLease go thro it u'll find it very helpful.
Also, search for user & daemon threads. These topics are also covered in the exam.

------------------

- Sathvathsan Sampath
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its nice to understand the various "phases" a thread can have.
Like "running/runnable", "blocked", "dead".
Methods like waitforId(), wait(), sleep(), suspend() and the i/o methods actually "blocks" the thread from running, ie. its waiting for some events to happen, so that it can resume its run.The scheduler won't consider the "blocked" thread, and its not occupying the CPU, but the thread is alive.
A thread successfully finishes execution when it returns from the run() method, and the thread is considered as "dead".
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody!
I put this small table to be discussed and corrected:
(later inserts: I do not know why there are so much blank space before table, please, scroll the page down)
What may/can/will stop a running thread?

running -> blocked

running -> dead

may

will

may

will

"blocking"

wait()

�+

+

-�

-

yield()

�+ (running -> ready)

+ (running -> ready)

�-

-

sleep()

�+

+

�-

-

suspend() (DEPRECATED)

�+

+

-

-

the method waitforId() in class mediaTracker is called

�+

+

-

-

A call to the halt or pause method of the Thread class

no such methods exist

I/o methods (a read() call on an InputStream)

�+

-

-

-

attempt to obtain a lock (to enter synchronized code block)

+�

-

-

-

exits

When the main method completes (assuming that question asks about another thread, not main thread )

-�

-

-

-

The call to the start() method of the Thread object returns

-�

-

-

-

the run() method that the thread is executing ends

�-

-

+

+

The program exits via a call to System.exit()

�-

-

+

+

another thread

If a thread creates a new thread

�+ (eventually)

-

-

-

Another thread is given a higher priority

�+

-

-

-

There is an uncaught exception in another thread

�-

-

-

-

stops

A call to the thread's stop() method.(DEPRECATED)

�-

-

+

+

A call to the thread's destroy() method.

�This method is not implemented

interrupting

Interrupt() is invoked

-

-

+

-

When the thread throws an interrupted exception

-

-

�may or may not

�-


Warning: do not use this table as reference, it may have mistakes! Please, post your comments.
[This message has been edited by Mapraputa Is (edited October 06, 2000).]
 
mohit joshi
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think what the Question's author meant was : when will the thread be dead. He felt free to use the term stop, because the deprecated method stop throws a ThreadDeath exception resulting in thread death.
How ever the word "stop" is used in many different contexts ( in sun's documentation also ).Here is an part of text that explains why stop was deprecated:
"What should I use instead of Thread.stop?
Most uses of stop should be replaced by code that simply modifies some variable to indicate that the target thread should stop running....".
so in present terminology stop is not equivalent to a thread dying.It could also mean "stop running".
This is my interpretation.
 
reply
    Bookmark Topic Watch Topic
  • New Topic