Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #24860
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2013-07-31 14:13 -0700 |
| References | <8fe57dc2-a323-4821-941c-4036663cbce5@googlegroups.com> <51f93cc4$0$291$14726298@news.sunsite.dk> |
| Message-ID | <a6efb240-0426-4019-896e-2f41cf74a26a@googlegroups.com> (permalink) |
| Subject | Re: What is so bad aboud Thread.stop() ? |
| From | Lew <lewbloch@gmail.com> |
Arne Vajhøj wrote: > taqmcg@gmail.com wrote: >> The use of Thread.stop() is strongly deprecated, but I'm a bit confused by the explanation given in the documentation: (e.g., http://docs.oracle.com/javase/6/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html) > >> Because it is inherently unsafe. Stopping a thread causes >> it to unlock all the monitors that it has locked. (The Do you know what they mean by a monitor? >> monitors are unlocked as the ThreadDeath exception propagates >> up the stack.) If any of the objects previously protected by >> these monitors were in an inconsistent state, other threads Inconsistent state is bad. >> may now view these objects in an inconsistent state. >> Such objects are said to be damaged. When threads operate on Damaged is bad. >> damaged objects, arbitrary behavior can result. This behavior Arbitrary behavior is bad. > > may be subtle and difficult to detect, or it may be pronounced. Subtle and difficult to detect is bad, really even worse than pronounced, because it confounds one's ability to fix it. >> Unlike other unchecked exceptions, ThreadDeath kills threads silently; Killed silently is bad. >> thus, the user has no warning that his program may be corrupted. No warning that the program is corrupted is bad. >> The corruption can manifest itself at any time after the actual >> damage occurs, even hours or days in the future. Random timing of corruption is bad. >> As I understand this, the ThreadDeath exception is treated exactly as >> any other exception -- finally blocks are honored, it can even be Except for the differences mentioned in the passage you cited. >> caught -- that might be thrown unexpectedly. E.g., if we got an >> OutOfMemoryError or we happen to explicitly throw a RuntimeException >> we're going to see exactly the same behavior with monitors released >> progressively as we go up the stack. It's certainly easy enough to Who said that 'Thread.stop()' release monitors progressively or goes up the stack? >> catch and rethrow the ThreadDeath in its run method if I really want >> to log it and address the one difference. Who will catch the exception? >> So what is the big hullaballoo about? Is there something special Broken code that fails silently at unexpected times in ways that are difficult to detect, let alone diagnose, that causes your program to be useless but you can't fix it. >> going on here with Thread.stop(), or is this just a specific instance Yes. >> of the fact the we should be very careful whenever a thread has been >> stopped by an unexpected exception? Even if it were, it wouldn't merit the word "just". >> Thread.stop() might be called at any time in the to-be-stopped >> thread, and that might be an issue, but at least in principle the >> thread that issues the stop could check the to-be-stopped thread and >> only stop it at 'appropriate' points where appropriate is defined by >> the user. No, because the starting thread has no insight into where the started thread is, or what points are appropriate, except for critical sections, which are for shit when a 'stop()' call destroys things. >> E.g., suppose I have some concern that a piece of code that I'm about >> to run might have an infinite loop in it (say I'm testing somebody >> else's regular expression parser with lots of different RE's), but >> it's not going to allocate any external resources (e.g., files, DB >> connections). I could set/clear a flag as I enter and leave the >> suspect code. Could I safely monitor this thread in another thread. >> After say 100 seconds if a given expression hasn't parsed can the >> monitor thread invoke a Thread.stop() safely if my flag shows that >> the RE thread is caught in the parser? No. > I think this part is the critical part > > # If any of the objects previously protected by > # these monitors were in an inconsistent state, other threads > # may now view these objects in an inconsistent state. > > There are cases where using it may result in problems. > > There may also be cases where it will work fine. But that is > not sufficient to consider something "safe". > > Go with the recommended approach of having the external > thread set a flag and the thread itself read it and close > down. Buy and closely study _Java Concurrency in Practice_ by Brian Goetz, et al. You will not get the in-depth understanding you need from a newsgroup. -- Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-07-31 06:36 -0700
Re: What is so bad aboud Thread.stop() ? Marcel Müller <news.5.maazl@spamgourmet.org> - 2013-07-31 18:31 +0200
Re: What is so bad aboud Thread.stop() ? Arne Vajhøj <arne@vajhoej.dk> - 2013-07-31 12:35 -0400
Re: What is so bad aboud Thread.stop() ? Lew <lewbloch@gmail.com> - 2013-07-31 14:13 -0700
Re: What is so bad aboud Thread.stop() ? usvirtualobservatory@gmail.com - 2013-08-01 07:38 -0700
Re: What is so bad aboud Thread.stop() ? Lew <lewbloch@gmail.com> - 2013-08-01 14:07 -0700
Re: What is so bad aboud Thread.stop() ? Steven Simpson <ss@domain.invalid> - 2013-08-01 23:15 +0100
Re: What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-08-01 16:16 -0700
Re: What is so bad aboud Thread.stop() ? "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-08-02 18:35 +0100
Re: What is so bad aboud Thread.stop() ? Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-08-03 19:21 -0700
Re: What is so bad aboud Thread.stop() ? Arne Vajhøj <arne@vajhoej.dk> - 2013-08-02 21:58 -0400
Re: What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-08-03 05:08 -0700
Re: What is so bad aboud Thread.stop() ? Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-07-31 21:09 -0700
Re: What is so bad aboud Thread.stop() ? usvirtualobservatory@gmail.com - 2013-08-01 08:00 -0700
Re: What is so bad aboud Thread.stop() ? Arne Vajhøj <arne@vajhoej.dk> - 2013-08-01 11:25 -0400
Re: What is so bad aboud Thread.stop() ? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-08-01 11:49 -0400
Re: What is so bad aboud Thread.stop() ? Arne Vajhøj <arne@vajhoej.dk> - 2013-08-02 21:51 -0400
Re: What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-08-01 09:30 -0700
Re: What is so bad aboud Thread.stop() ? markspace <markspace@nospam.nospam> - 2013-08-01 10:01 -0700
Re: What is so bad aboud Thread.stop() ? Arne Vajhøj <arne@vajhoej.dk> - 2013-08-02 21:55 -0400
Re: What is so bad aboud Thread.stop() ? Sven Köhler <remove-sven.koehler@gmail.com> - 2013-08-01 18:28 +0300
Re: What is so bad aboud Thread.stop() ? "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-08-02 18:50 +0100
Re: What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-08-02 11:34 -0700
Re: What is so bad aboud Thread.stop() ? Arne Vajhøj <arne@vajhoej.dk> - 2013-08-02 22:04 -0400
Re: What is so bad aboud Thread.stop() ? "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-08-03 10:10 +0100
Re: What is so bad aboud Thread.stop() ? "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-08-03 10:28 +0100
Re: What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-08-03 05:00 -0700
Re: What is so bad aboud Thread.stop() ? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2013-08-11 17:46 +0000
Re: What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-08-13 11:47 -0700
Re: What is so bad aboud Thread.stop() ? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2013-08-13 20:18 +0000
Re: What is so bad aboud Thread.stop() ? Patricia Shanahan <pats@acm.org> - 2013-08-13 13:51 -0700
Re: What is so bad aboud Thread.stop() ? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2013-08-14 22:42 +0000
Re: What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-08-13 14:10 -0700
Re: What is so bad aboud Thread.stop() ? Lew <lewbloch@gmail.com> - 2013-08-13 15:22 -0700
Re: What is so bad aboud Thread.stop() ? Arivald <NOSPAMarivald@interia.pl> - 2013-08-14 01:08 +0200
Re: What is so bad aboud Thread.stop() ? markspace <markspace@nospam.nospam> - 2013-08-13 16:45 -0700
Re: What is so bad aboud Thread.stop() ? Arivald <NOSPAMarivald@interia.pl> - 2013-08-14 08:42 +0200
Re: What is so bad aboud Thread.stop() ? Marcel Müller <news.5.maazl@spamgourmet.org> - 2013-08-14 09:48 +0200
Re: What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-08-14 08:55 -0700
Re: What is so bad aboud Thread.stop() ? markspace <markspace@nospam.nospam> - 2013-08-14 19:10 -0700
Re: What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-08-15 06:51 -0700
Re: What is so bad aboud Thread.stop() ? Lew <lewbloch@gmail.com> - 2013-08-15 17:35 -0700
Re: What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-08-16 06:30 -0700
Re: What is so bad aboud Thread.stop() ? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2013-08-14 22:43 +0000
Re: What is so bad aboud Thread.stop() ? taqmcg@gmail.com - 2013-08-15 12:12 -0700
csiph-web