Skip to content

Commit 87e012c

Browse files
committed
make TaskMonitoring more configurable
1 parent 57d9b83 commit 87e012c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

net.lecousin.core/src/main/java/net/lecousin/framework/concurrent/TaskMonitoring.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ public final class TaskMonitoring {
1919

2020
public static boolean checkLocksOfBlockingTasks = false;
2121

22-
public static int MINUTES_BEFORE_TO_PUT_TASK_ASIDE = 5;
23-
public static int MINUTES_BEFORE_KILL_TASK = 10;
22+
public static int MONITORING_INTERVAL = 60 * 1000;
23+
public static int SECONDS_BEFORE_TO_PUT_TASK_ASIDE = 5 * 60;
24+
public static int SECONDS_BEFORE_KILL_TASK = 10 * 60;
2425

2526
private static TaskMonitor monitor;
2627

@@ -69,7 +70,7 @@ private static class TaskMonitor implements Runnable, Closeable {
6970
public void run() {
7071
while (!closed) {
7172
synchronized (lock) {
72-
try { lock.wait(60000); }
73+
try { lock.wait(MONITORING_INTERVAL); }
7374
catch (InterruptedException e) { break; }
7475
if (closed)
7576
break;
@@ -99,14 +100,14 @@ private static void check(TaskWorker worker) {
99100
Task<?,?> task = worker.currentTask;
100101
if (task == null) return;
101102
long start = worker.currentTaskStart;
102-
long minutes = (now - start) / (1000000L * 1000 * 60);
103-
if (minutes < MINUTES_BEFORE_TO_PUT_TASK_ASIDE) return;
104-
if (minutes < MINUTES_BEFORE_KILL_TASK) {
105-
Threading.logger.warn("Task " + task + " is running since more than 5 minutes !");
103+
long seconds = (now - start) / (1000000L * 1000);
104+
if (seconds < SECONDS_BEFORE_TO_PUT_TASK_ASIDE) return;
105+
if (seconds < SECONDS_BEFORE_KILL_TASK) {
106+
Threading.logger.warn("Task " + task + " is running since " + seconds + " seconds ! put it aside and start a new thread");
106107
worker.manager.putWorkerAside(worker);
107108
return;
108109
}
109-
Threading.logger.error("Task " + task + " is running since more than 10 minutes ! kill it.");
110+
Threading.logger.error("Task " + task + " is running since " + seconds + " seconds ! kill it.");
110111
worker.manager.killWorker(worker);
111112
}
112113

0 commit comments

Comments
 (0)