|
6 | 6 | import java.util.concurrent.Executors; |
7 | 7 | import java.util.concurrent.ScheduledExecutorService; |
8 | 8 | import java.util.concurrent.SynchronousQueue; |
| 9 | +import java.util.concurrent.ThreadFactory; |
9 | 10 | import java.util.concurrent.ThreadPoolExecutor; |
10 | 11 | import java.util.concurrent.TimeUnit; |
| 12 | +import java.util.concurrent.atomic.AtomicInteger; |
11 | 13 |
|
12 | 14 | import org.pf4j.Plugin; |
13 | 15 |
|
@@ -57,7 +59,36 @@ public class ServerController extends Plugin implements MindustryToolPlugin { |
57 | 59 | 20, |
58 | 60 | 5, |
59 | 61 | TimeUnit.SECONDS, |
60 | | - new SynchronousQueue<Runnable>()); |
| 62 | + new SynchronousQueue<Runnable>(), |
| 63 | + new DefaultThreadFactory()); |
| 64 | + |
| 65 | + private class DefaultThreadFactory implements ThreadFactory { |
| 66 | + private static final AtomicInteger poolNumber = new AtomicInteger(1); |
| 67 | + private final ThreadGroup group; |
| 68 | + private final AtomicInteger threadNumber = new AtomicInteger(1); |
| 69 | + private final String namePrefix; |
| 70 | + |
| 71 | + @SuppressWarnings("deprecation") |
| 72 | + DefaultThreadFactory() { |
| 73 | + @SuppressWarnings("removal") |
| 74 | + SecurityManager s = System.getSecurityManager(); |
| 75 | + group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); |
| 76 | + namePrefix = "background-pool-" + |
| 77 | + poolNumber.getAndIncrement() + |
| 78 | + "-thread-"; |
| 79 | + } |
| 80 | + |
| 81 | + public Thread newThread(Runnable r) { |
| 82 | + Thread t = new Thread(group, r, |
| 83 | + namePrefix + threadNumber.getAndIncrement(), |
| 84 | + 0); |
| 85 | + if (t.isDaemon()) |
| 86 | + t.setDaemon(false); |
| 87 | + if (t.getPriority() != Thread.NORM_PRIORITY) |
| 88 | + t.setPriority(Thread.NORM_PRIORITY); |
| 89 | + return t; |
| 90 | + } |
| 91 | + } |
61 | 92 |
|
62 | 93 | public final ScheduledExecutorService BACKGROUND_SCHEDULER = Executors |
63 | 94 | .newSingleThreadScheduledExecutor(); |
|
0 commit comments