Avoid errors

This commit is contained in:
Andrea Cavalli 2021-08-04 00:44:06 +02:00
parent 2f3cea9d5b
commit bcd99f4727
2 changed files with 16 additions and 1 deletions

View File

@ -280,7 +280,9 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
@Override
public void run() {
scheduledTasksLifecycle.startScheduledTask();
if (!scheduledTasksLifecycle.tryStartScheduledTask()) {
return;
}
try {
if (scheduledTasksLifecycle.isCancelled() || cancelled) return;
task.run();

View File

@ -27,6 +27,19 @@ public class ScheduledTaskLifecycle {
this.lock.readLock();
}
/**
* Mark this task as running.
* After calling this method, please call {@method endScheduledTask} inside a finally block!
* @return false if failed
*/
public boolean tryStartScheduledTask() {
if (cancelled) {
return false;
}
this.lock.readLock();
return true;
}
/**
* Mark this task as ended. Must be called after {@method startScheduledTask}
*/