4646import java .util .concurrent .ExecutionException ;
4747import java .util .concurrent .ExecutorService ;
4848import java .util .concurrent .Executors ;
49+ import java .util .concurrent .LinkedBlockingQueue ;
50+ import java .util .concurrent .ThreadFactory ;
51+ import java .util .concurrent .ThreadPoolExecutor ;
4952import java .util .concurrent .TimeUnit ;
53+ import java .util .concurrent .atomic .AtomicInteger ;
5054import java .util .function .Consumer ;
5155
5256import org .apache .logging .log4j .Level ;
@@ -67,12 +71,23 @@ private JDKPoller() {}
6771 private static final Logger logger = LogManager .getLogger ();
6872 private static final Map <WatchKey , Consumer <List <WatchEvent <?>>>> watchers = new ConcurrentHashMap <>();
6973 private static final WatchService service ;
70- private static final int nCores = Runtime .getRuntime ().availableProcessors ();
7174 /**
7275 * We have to be a bit careful with registering too many paths in parallel
7376 * Linux can be thrown into a deadlock if you try to start 1000 threads and then do a register at the same time.
7477 */
75- private static final ExecutorService registerPool = Executors .newFixedThreadPool (nCores );
78+ private static final ExecutorService registerPool = new ThreadPoolExecutor (
79+ 0 , Runtime .getRuntime ().availableProcessors (),
80+ 10 , TimeUnit .SECONDS ,
81+ new LinkedBlockingQueue <>(), new ThreadFactory () {
82+ private final AtomicInteger id = new AtomicInteger (0 );
83+ private final ThreadGroup group = new ThreadGroup ("registry pool" );
84+ @ Override
85+ public Thread newThread (Runnable r ) {
86+ var t = new Thread (group , r , "JavaWatch-registry-pool-" + id .incrementAndGet ());
87+ t .setDaemon (true );
88+ return t ;
89+ }
90+ });
7691
7792 static {
7893 try {
0 commit comments