Just as mentioned, can we make one thread as daemon thread, and execute some detection codes on detecting other threads status? i hope the daemon thread will be executed every 5 mins(more or less, inaccuracy can't be huge, several seconds delay are acceptable)
Asked
Active
Viewed 97 times
-1
-
See this: http://stackoverflow.com/questions/426758/running-a-java-thread-in-intervals – Azodious Apr 02 '13 at 11:06
2 Answers
0
Have a look at this:
public static void main(String[] args) throws InterruptedException {
ScheduledThreadPoolExecutor svc = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t1 = new Thread(r);
t1.setDaemon(true);
return t1;
}
});
svc.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
System.out.println("Himanshu "+Thread.currentThread().getName());
}
}, 5, 5, TimeUnit.SECONDS);
svc.awaitTermination(10000, TimeUnit.SECONDS);
}

Himanshu Bhardwaj
- 4,038
- 3
- 17
- 36