Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About multi threading

How to kill the thread? ..... How to restart them again in multi threading?

like image 900
Chetan Avatar asked Mar 22 '10 03:03

Chetan


1 Answers

Since your post is tagged "Java," I have a good idea of what you are saying. Let's say you start a thread by doing:

Thread foo = new Thread(someRunnable);
foo.start();

Now that destroy and friends are deprecated, you need a way to kill the thread. Luckily for you, there has always been the concept of "interrupts." Simply change your runnable so that, on interrupt, it exits. Then call the thread's interrupt method.

foo.interrupt();

If you wrote your Runnable to handle this correctly, it will stop whatever it is doing and terminate.

like image 173
avpx Avatar answered Sep 28 '22 13:09

avpx