How do I set a time limit for a runnable thread created in Java?
There is more than 1 thread created and running at a time. How do I know the time since its creation for each thread?
This is the code I use:
List<Thread> threads = new ArrayList<Thread>();
for(int i=0;i<no_of_threads;i++){
Runnable task = new MyRunnable(text,filename,prop,filename,L,L1,seq_no);
Thread worker = new Thread(task);
worker.start();
// Remember the thread for later usage
threads.add(worker);}
public class MyRunnable implements Runnable {
MyRunnable(String text,String filename,ArrayList<String> prop,String ip_file,Logger l,Logger l1,int seq_no) {
this.text=text;
this.filename=filename;
this.prop=prop;
this.ip_file=ip_file;
this.L=l;
this.L1=l1;
this.seq_no=seq_no;
}
@Override
public void run() {
/* other computation*/
}