2023-09-17 22:13:42 +03:00
|
|
|
package Common.Utils;
|
|
|
|
|
import ProjectData.Project.db_project_info;
|
|
|
|
|
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(db_project_info.interrupt);
|
|
|
|
|
try {
|
|
|
|
|
while (true) {
|
|
|
|
|
Thread.sleep(sleep_ms);
|
|
|
|
|
if (interruptFile.exists()) {
|
2023-09-30 18:19:31 +03:00
|
|
|
FileUtils.writeStringToFile(new File("ABORTED"), "");
|
2023-09-17 22:13:42 +03:00
|
|
|
FileUtils.forceDelete(interruptFile);
|
|
|
|
|
action.call();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|