I am working on multithreading in java and created 1 thread here is the code:
class SampleThread extends Thread
{
int time;
String name;
boolean autocall;
public SampleThread(int time, String name)
{
this.time = time;
this.name = name;
}
public void run()
{
try{
time = time +1;
updateView(time, name);
//sleep(3000);
}catch(Exception e)
{
e.printStackTrace();
}
//this.stop();
}
}
Now I want to run this thread every 3 seconds how to achieve this??
I’d recommend not doing it this way. Have a look at the new classes (well, not so new) in the
java.util.concurrentpackage, especially ScheduledThreadPoolExecutor.