Accept me as I am, or Watch me as I go.
Accept me as I am, or Watch me as I go.
Jayesh A Lalwani wrote:What don't you understand from that link? It says that objects might be damaged on stop. Do you want to know why objects might be damaged?
Accept me as I am, or Watch me as I go.
How stopping a Thread will put object into an unstable state ?
Ulf Dittmer wrote:
Let's be precise: Stopping a thread doesn't put any object into an unusable state - using Thread.stop() does that. Stopping a thread as suggested above is fine. While it's good to be curious, in this particular case I would just accept that you should not use those methods and move on. The explanation is highly technical, and won't make sense unless you know the internals of the JVM very well (very few people do).
Accept me as I am, or Watch me as I go.
Steve
Steve Luke wrote:
There are many things that could be broken if you don't know that a task us being stopped and process it accordingly. The Thread.stop() method wouldn't give you the chance to process and clean up, so whatever you were doing will be in a bad state and every other thread will suffer from it. By deprecating it Java is forcing you to think about how to process a stop request so the issues appropriate to your task can be handled gracefully.
Accept me as I am, or Watch me as I go.
Chan Ag wrote:Suppose you have a thread that is supposed to do this.
Transfer 2000 bucks from Person X's account to Person Y's account.
So the run method has, let's say, following logic.
1. Check if both the account numbers are valid.
2. Check if X has amount >2000 in his account.
3. Debit 2000 from X's account.
4. Credit 2000 into Y's account.
Now let us say somebody killed/stopped the thread after point 3. So now, the two objects here ( let us say X's account and Y's account ), are in inconsistent state.
2000 bucks that were debited from X's account are lost.
This is an example of damaged objects. Y's account is in a damaged state and so is X's account.
Hope that explains.
And why would a thread have another thread be able to control when it should stop execution, or to kill it in the middle of some processing?
Wouldn't it create a big blunder if other threads were able to reset the interrupted status bit of a thread via the isInterrupted method? And here we are talking about killing a thread!
Accept me as I am, or Watch me as I go.
Rohit Kumar Singh wrote:
Thanks sir for such a fine Example ..