Skip to content

Commit 1bb4de2

Browse files
backwaterredtstuefe
authored andcommitted
8285956: (fs) Excessive default poll interval in PollingWatchService
Reviewed-by: stuefe, bpb
1 parent 3092b56 commit 1bb4de2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/java.base/share/classes/sun/nio/fs/PollingWatchService.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
class PollingWatchService
6262
extends AbstractWatchService
6363
{
64+
// Wait between polling thread creation and first poll (seconds)
65+
private static final int POLLING_INIT_DELAY = 1;
66+
// Default time between polls (seconds)
67+
private static final int DEFAULT_POLLING_INTERVAL = 2;
68+
6469
// map of registrations
6570
private final Map<Object, PollingWatchKey> map = new HashMap<>();
6671

@@ -115,7 +120,7 @@ WatchKey register(final Path path,
115120
throw new IllegalArgumentException("No events to register");
116121

117122
// Extended modifiers may be used to specify the sensitivity level
118-
int sensitivity = 10;
123+
int sensitivity = DEFAULT_POLLING_INTERVAL;
119124
if (modifiers.length > 0) {
120125
for (WatchEvent.Modifier modifier: modifiers) {
121126
if (modifier == null)
@@ -247,6 +252,7 @@ void update(long lastModified, int tickCount) {
247252
* directory and queue keys when entries are added, modified, or deleted.
248253
*/
249254
private class PollingWatchKey extends AbstractWatchKey {
255+
250256
private final Object fileKey;
251257

252258
// current event set
@@ -305,10 +311,10 @@ void enable(Set<? extends WatchEvent.Kind<?>> events, long period) {
305311
// update the events
306312
this.events = events;
307313

308-
// create the periodic task
314+
// create the periodic task with initialDelay set to the specified constant
309315
Runnable thunk = new Runnable() { public void run() { poll(); }};
310316
this.poller = scheduledExecutor
311-
.scheduleAtFixedRate(thunk, period, period, TimeUnit.SECONDS);
317+
.scheduleAtFixedRate(thunk, POLLING_INIT_DELAY, period, TimeUnit.SECONDS);
312318
}
313319
}
314320

0 commit comments

Comments
 (0)