/
TaskManager.java
41 lines (32 loc) · 1016 Bytes
/
TaskManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package net.catalyst.core;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import net.catalyst.util.Settings;
public class TaskManager {
private ScheduledExecutorService eService = Executors.newScheduledThreadPool(Settings.SERVER_THREAD_COUNT);
public void assignProcessor(Runnable r) {
eService.submit(r);
}
public void scheduledProcessor(Runnable r, int time) {
eService.schedule(r, time, TimeUnit.MILLISECONDS);
}
public void checkAndBlockThread() {
boolean going = false;
if(Server.getServer().isUpdating()) {
while(Server.getServer().isUpdating()) {
if(going != true) {
System.out.println("Waiting for update to finish! " + Thread.currentThread().getName());
going = true;
}
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(going)
System.out.println("Update Finished " + Thread.currentThread().getName());
}
}
}