I have a class which has a runnable thread in it. I send a variable to this class more than one time at the same time. The class has run() method and starts own thread for the variable sent from another class. After some processes, i need to stop Threads with interrupt but i have to spesify the name of the thread that i want to stop (such as MyThread.interrupt() ). The problem is, i create the thread with the same object name in the class everytime. So i have to name this thread object differently every time and stop it by its name. But i dont know how to.. This is my code;
public class KasaThread {
public static Thread till ;
public static String [] table_list_kasa;
public static void get (final String IP,final String MagID){
till = new Thread () {
public void run () {
if(IP != null){
try{
...
...
...
}catch(Exception e} {}
in another class, I interrupt this thread by its name like (till.interrupt() ).. But as i said, every thread which is created in this class, has the same name (till).
How to solve this ?
Thanks in advance.
I think you can solve this problem with methods setName(String name)
and getName()
+ some counter.