Skip to content

Commit 1249c97

Browse files
k15tfuvprovodin
authored andcommitted
JBR-9515 Allow size of per-directory buffer used to retrieve events to be configurable to avoid OVERFLOW_EVENT
1 parent 7799ff6 commit 1249c97

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/java.base/windows/classes/sun/nio/fs/WindowsWatchService.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Set;
3737

3838
import jdk.internal.misc.Unsafe;
39+
import jdk.internal.util.ArraysSupport;
3940

4041
import static sun.nio.fs.WindowsNativeDispatcher.*;
4142
import static sun.nio.fs.WindowsConstants.*;
@@ -284,9 +285,26 @@ private static class Poller extends AbstractPoller {
284285
private static final short OFFSETOF_FILENAMELENGTH = 8;
285286
private static final short OFFSETOF_FILENAME = 12;
286287

287-
// size of per-directory buffer for events (FIXME - make this configurable)
288-
// Need to be less than 4*16384 = 65536. DWORD align.
289-
private static final int CHANGES_BUFFER_SIZE = 16 * 1024;
288+
// size of per-directory buffer for events
289+
// Need to be less than 4*16384 = 65536 when monitoring a directory over the network. DWORD align.
290+
private static final int DEFAULT_CHANGES_BUFFER_SIZE = 16 * 1024;
291+
static final int CHANGES_BUFFER_SIZE;
292+
static {
293+
String rawValue = System.getProperty(
294+
"jdk.nio.file.WatchService.bufferSizeToRetrieveEventsPerDirectory",
295+
String.valueOf(DEFAULT_CHANGES_BUFFER_SIZE));
296+
int intValue;
297+
try {
298+
// Clamp to size of per-directory buffer used to retrieve events.
299+
intValue = Math.clamp(
300+
Long.decode(rawValue),
301+
1,
302+
ArraysSupport.SOFT_MAX_ARRAY_LENGTH);
303+
} catch (NumberFormatException e) {
304+
intValue = DEFAULT_CHANGES_BUFFER_SIZE;
305+
}
306+
CHANGES_BUFFER_SIZE = intValue;
307+
}
290308

291309
private final WindowsFileSystem fs;
292310
private final WindowsWatchService watcher;

0 commit comments

Comments
 (0)