Skip to content

Commit ed4101f

Browse files
vaadin-botArtur-
andauthored
fix: Do not starve the common ForkJoinPool with blocking listener tasks (#21342) (#21358)
Calling watchAsync without any specific executor uses the common ForkJoinPool. This is bad as all the watchers will remain in a blocking state until there is a change and will thus always use up a large part of the ForkJoinPool. If other tasks try to use the common ForkJoinPool, it might run out of concurrent threads and will no longer start any tasks at all Co-authored-by: Artur <artur@vaadin.com>
1 parent f0f5cf1 commit ed4101f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

vaadin-dev-server/src/main/java/com/vaadin/base/devserver/FileWatcher.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import java.io.File;
1919
import java.io.IOException;
2020
import java.util.Objects;
21+
import java.util.concurrent.ExecutorService;
22+
import java.util.concurrent.Executors;
2123

2224
import io.methvin.watcher.DirectoryWatcher;
2325
import org.slf4j.Logger;
@@ -32,6 +34,9 @@ public class FileWatcher {
3234

3335
private DirectoryWatcher watcher;
3436

37+
private static ExecutorService executorService = Executors
38+
.newCachedThreadPool();
39+
3540
/**
3641
* Creates an instance of the file watcher for the given directory.
3742
* <p>
@@ -62,7 +67,7 @@ public FileWatcher(SerializableConsumer<File> onChangeConsumer,
6267
* Starts the file watching.
6368
*/
6469
public void start() {
65-
watcher.watchAsync().exceptionally((e) -> {
70+
watcher.watchAsync(executorService).exceptionally((e) -> {
6671
getLogger().error("Error starting file watcher", e);
6772
return null;
6873
});

0 commit comments

Comments
 (0)