Reputation: 707
I apologize in advance if this question sounds presumptuous. I'm fairly new to this. So here it goes . . .
I've been researching the "java thread stopping" issue for a while. I read many articles on stackoverflow, and most of them come to a conclusion that thread stopping is very awkward in java. Some good ways include:
join
(this answer got 87 upvotes) and wait until a thread finished. volatile
flag to signal the other threads. This answer got 113 upvotes Thread.interrupt()
and later check isInterrupted
shutdownNow
method does not give any guarantees, and counts on that isInterrupted
boolean But neither of the above methods allow an immediate thread stop. For example, if a program is running some SQL
and waiting for an external database respond, then ALL of the above method will "humbly wait" until that SQL
finishes. So the stopping is NOT immediate at all. Only when that SQL
finishes (which may take hours), will the program check for isInterrupted
or other flag, and then stop
Here is the punchline . . .
I know Eclipse is written in java
according to this stackoverflow answer. And whenever I click that red stop button , Eclipse will stop my application immediately. I presume it is NOT using Thread.stop
since it's deprecated. But I it can't possible be using those method recommended on stackoverflow. How does Eclipse manage to stop threads so fast?
Upvotes: 1
Views: 714
Reputation: 111217
When you run a Java program from within Eclipse a completely new JVM is created in a new Process to run the program. A process is not the same thing as a thread.
Within Eclipse the process is represented by the java.lang.Process
class. Eclipse calls the destroy()
method of Process
when you stop the program.
So what Eclipse is using for this is nothing to do with threads.
Upvotes: 7