|
36 | 36 | import java.util.Set; |
37 | 37 |
|
38 | 38 | import jdk.internal.misc.Unsafe; |
| 39 | +import jdk.internal.util.ArraysSupport; |
39 | 40 |
|
40 | 41 | import static sun.nio.fs.WindowsNativeDispatcher.*; |
41 | 42 | import static sun.nio.fs.WindowsConstants.*; |
@@ -284,9 +285,26 @@ private static class Poller extends AbstractPoller { |
284 | 285 | private static final short OFFSETOF_FILENAMELENGTH = 8; |
285 | 286 | private static final short OFFSETOF_FILENAME = 12; |
286 | 287 |
|
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 | + } |
290 | 308 |
|
291 | 309 | private final WindowsFileSystem fs; |
292 | 310 | private final WindowsWatchService watcher; |
|
0 commit comments