Terminating a Thread?

The API mentions nothing about how to terminate a thread. Currently when one of my threads get a message that it should stop working it just calls System.exit(0)...is that the preferred way?
[197 byte] By [lokpesta] at [2007-10-3 5:21:52]
# 1
NOOOOO. NOT THIS AGAIN!I just let mine reach the end of the run() method. I dont know if thats the best way though.
CaptainMorgan08a at 2007-7-14 23:28:51 > top of Java-index,Java Essentials,Java Programming...
# 2

> The API mentions nothing about how to terminate a

> thread. Currently when one of my threads get a

> message that it should stop working it just calls

> System.exit(0)...is that the preferred way?

No that's the worst possible thing to do.

Just exit your run method. A return statement would do. Or some other logic that just ends.

Don't use System.exit(0) for that. (and hardly for anything really)

cotton.ma at 2007-7-14 23:28:51 > top of Java-index,Java Essentials,Java Programming...
# 3

> The API mentions nothing about how to terminate a

> thread. Currently when one of my threads get a

> message that it should stop working it just calls

> System.exit(0)...is that the preferred way?

That terminates the entire application - including any other threads that are running.

The vast majority of the time you do not want to do that.

jschella at 2007-7-14 23:28:51 > top of Java-index,Java Essentials,Java Programming...