fury-old
fury-old copied to clipboard
filewatcher uses too many threads
When watching Fury, waiting for changes, it creates 30 new threads in order to watch the various source directories. It feels like this ought to be a single thread.
The example here which avoids using Better Files looks very simple. We can block the current thread. We could even wrap the events in a Stream.
The threads named "FileSystemWatchService" are created by the OpenJDK implementation of file system poller. I don't think the directory-watcher library has any control over them.
Since Fury creates one directory watcher per source directory, we are bound to have 30 "FileSystemWatchService" threads for the full Fury build (fewer for partial builds, such as fury/core).
I guess it possible to create a single watcher for the whole directory tree (or just the smallest common parent of all the source directories) and filter out unrelated events, but this doesn't sound like a very good idea.