Re: When the stop() in Thread class changed to final method?
- From: nukleus@xxxxxxxxxxxx (nukleus)
- Date: Fri, 02 Feb 2007 11:50:49 GMT
In article <epup7l$4o0$1@xxxxxxxxxxxxxxxxxx>, Rogan Dawes
<discard@xxxxxxxxxxxx> wrote:
RC wrote:
Daniel Pitts wrote:
On Feb 1, 7:27 am, RC <raymond.c...@xxxxxxxxxxxxxxx> wrote:
If you go to this link
http://java.sun.com/j2se/1.5.0/docs/guide/misc/threadPrimitiveDepreca...
That document you linked to is suggesting that you override the stop
method in Applet, not Thread.
Then, do you know how I can stop a thread since Thread.stop()
has deprecated. Can I just make a thread = null?
Stopping a thread is just the worst possible thing
you can imagine. In many cases, you'll simply crash you
entire app if you don't catch that exception in
the right place.
Thread should be stopped by exiting it main run()
loop. The simpliest thing is to set some variable
that is tested in the run loop. That variable could
be set by just about any method or a result of
some user action, such as "cancel" or from some
event handler code.
But when you simply slaugher thread with stop(),
there may be all sorts of things happening
in your app, things may be locked, some other
threads may be waiting for some operation to complete,
and so on. Because once you even utter the word
"thread", it implies theare are other threads in
your app, and they all should coordinate the
access to common resources, such as files, sockets,
gui elements or you name it.
So...
What you are creating by doing that stop() thing,
is making your entire app inconsistent, when one
part thinks that it has a valid access to some
variable or resource, but the other part,
sitting on the same resource is dead.
You'll never make your program stable.
That is for sure.
Just about all you can achive with it
is an ugly hack.
My suggestion is to completely forget this idea,
because exiting thread properly is about the simpliest
thing in the world, at least in most cases.
And make sure that if that thread is associated
with some frame in your app, you first exit thread,
and then make sure to close that frame by doing
dispose().
This way, your entire program's logic
will operate as intuitively expected by the user.
Good luck.
Did you not read the link that YOU provided above?.
It has all the advice and examples you need to answer that question.
Rogan
- Follow-Ups:
- References:
- Re: When the stop() in Thread class changed to final method?
- From: Daniel Pitts
- Re: When the stop() in Thread class changed to final method?
- From: RC
- Re: When the stop() in Thread class changed to final method?
- From: Rogan Dawes
- Re: When the stop() in Thread class changed to final method?
- Prev by Date: Re: Microsoft Java almost gone in Vista
- Next by Date: J2ME<->IMAGE<->SERVLET
- Previous by thread: Re: When the stop() in Thread class changed to final method?
- Next by thread: Re: When the stop() in Thread class changed to final method?
- Index(es):
Relevant Pages
|