Files
VisualSapfor/src/Common/Utils/InterruptThread.java
2024-10-14 15:19:13 +03:00

27 lines
841 B
Java

package Common.Utils;
import _VisualDVM.Constants;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.concurrent.Callable;
public class InterruptThread extends Thread {
//------------
public InterruptThread(int sleep_ms, Callable action) {
super(() -> {
File interruptFile = new File(Constants.INTERRUPT);
try {
while (true) {
Thread.sleep(sleep_ms);
if (interruptFile.exists()) {
FileUtils.writeStringToFile(new File(Constants.ABORTED), "");
FileUtils.forceDelete(interruptFile);
action.call();
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
});
}
}