|
61 | 61 | class PollingWatchService |
62 | 62 | extends AbstractWatchService |
63 | 63 | { |
| 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 | + |
64 | 69 | // map of registrations |
65 | 70 | private final Map<Object, PollingWatchKey> map = new HashMap<>(); |
66 | 71 |
|
@@ -115,7 +120,7 @@ WatchKey register(final Path path, |
115 | 120 | throw new IllegalArgumentException("No events to register"); |
116 | 121 |
|
117 | 122 | // Extended modifiers may be used to specify the sensitivity level |
118 | | - int sensitivity = 10; |
| 123 | + int sensitivity = DEFAULT_POLLING_INTERVAL; |
119 | 124 | if (modifiers.length > 0) { |
120 | 125 | for (WatchEvent.Modifier modifier: modifiers) { |
121 | 126 | if (modifier == null) |
@@ -247,6 +252,7 @@ void update(long lastModified, int tickCount) { |
247 | 252 | * directory and queue keys when entries are added, modified, or deleted. |
248 | 253 | */ |
249 | 254 | private class PollingWatchKey extends AbstractWatchKey { |
| 255 | + |
250 | 256 | private final Object fileKey; |
251 | 257 |
|
252 | 258 | // current event set |
@@ -305,10 +311,10 @@ void enable(Set<? extends WatchEvent.Kind<?>> events, long period) { |
305 | 311 | // update the events |
306 | 312 | this.events = events; |
307 | 313 |
|
308 | | - // create the periodic task |
| 314 | + // create the periodic task with initialDelay set to the specified constant |
309 | 315 | Runnable thunk = new Runnable() { public void run() { poll(); }}; |
310 | 316 | this.poller = scheduledExecutor |
311 | | - .scheduleAtFixedRate(thunk, period, period, TimeUnit.SECONDS); |
| 317 | + .scheduleAtFixedRate(thunk, POLLING_INIT_DELAY, period, TimeUnit.SECONDS); |
312 | 318 | } |
313 | 319 | } |
314 | 320 |
|
|
0 commit comments