1 回答

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊
您可以使用自定義名稱創(chuàng)建線程并將您的備份進(jìn)程放入。下次你試著按名字找到他的時(shí)候。如果他會被找到 - gackup 正在工作。
Set<Thread> threads = Thread.getAllStackTraces().keySet();
boolean isWorking = threads.stream().anyMatch(t -> t.getName().equals("My backup is working"));
if (!isWorking) {
Runnable task = () -> {
Thread.currentThread().setName("My backup is working");
//some code of run backup
System.out.println("start backup");
};
Thread thread = new Thread(task);
System.out.println("Done!");
thread.start();
}
添加回答
舉報(bào)