-1

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)

user2009854
  • 29
  • 1
  • 5

2 Answers2

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
0

Look here first, like @Azodious said. The job you want to schedule is using ThreadMXBeans. See sample core here.

Community
  • 1
  • 1
Ralf H
  • 1,392
  • 1
  • 9
  • 17