2023-09-17 22:13:42 +03:00
|
|
|
package Common.Utils;
|
2023-10-04 22:01:09 +03:00
|
|
|
import Common.Constants;
|
2023-09-17 22:13:42 +03:00
|
|
|
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(() -> {
|
2023-10-04 22:01:09 +03:00
|
|
|
File interruptFile = new File(Constants.INTERRUPT);
|
2023-09-17 22:13:42 +03:00
|
|
|
try {
|
|
|
|
|
while (true) {
|
|
|
|
|
Thread.sleep(sleep_ms);
|
|
|
|
|
if (interruptFile.exists()) {
|
2023-10-04 22:01:09 +03:00
|
|
|
FileUtils.writeStringToFile(new File(Constants.ABORTED), "");
|
|
|
|
|
FileUtils.forceDelete(interruptFile);
|
2023-10-09 22:51:54 +03:00
|
|
|
action.call();
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|