|
37 | 37 | import com.google.common.annotations.VisibleForTesting; |
38 | 38 | import com.google.common.util.concurrent.SettableFuture; |
39 | 39 | import java.util.concurrent.ExecutorService; |
| 40 | +import java.util.concurrent.LinkedBlockingQueue; |
| 41 | +import java.util.concurrent.ThreadPoolExecutor; |
| 42 | +import java.util.concurrent.TimeUnit; |
40 | 43 | import java.util.concurrent.atomic.AtomicInteger; |
41 | 44 | import java.util.concurrent.atomic.AtomicReference; |
42 | 45 | import java.util.logging.Level; |
@@ -88,18 +91,20 @@ final class RegionalAccessBoundaryManager { |
88 | 91 | private static final ExecutorService EXECUTOR; |
89 | 92 |
|
90 | 93 | static { |
91 | | - java.util.concurrent.ThreadPoolExecutor executor = |
92 | | - new java.util.concurrent.ThreadPoolExecutor( |
| 94 | + ThreadPoolExecutor executor = |
| 95 | + new ThreadPoolExecutor( |
93 | 96 | 5, // corePoolSize: threads to keep alive |
94 | 97 | 5, // maximumPoolSize: max threads allowed |
95 | 98 | 1, // keepAliveTime: time to wait before terminating idle threads |
96 | | - java.util.concurrent.TimeUnit.HOURS, // unit for keepAliveTime |
97 | | - new java.util.concurrent.LinkedBlockingQueue<>(), // work queue |
| 99 | + TimeUnit.HOURS, // unit for keepAliveTime |
| 100 | + new LinkedBlockingQueue<>(), // work queue |
98 | 101 | r -> { |
99 | 102 | Thread t = new Thread(r, "RAB-refresh-" + threadCount.getAndIncrement()); |
100 | 103 | t.setDaemon(true); |
101 | 104 | return t; |
102 | 105 | }); |
| 106 | + // Allow core threads to time out so the executor can shrink to 0 when idle. |
| 107 | + // Ensures threads are released when idle to avoid unnecessary resource usage. |
103 | 108 | executor.allowCoreThreadTimeOut(true); |
104 | 109 | EXECUTOR = executor; |
105 | 110 | } |
|
0 commit comments