8285956: (fs) Excessive default poll interval in PollingWatchService

Reviewed-by: stuefe, bpb
This commit is contained in:
Tyler Steele 2022-05-05 04:05:55 +00:00 committed by Thomas Stuefe
parent 3092b5615d
commit 1bb4de2e28

View file

@ -61,6 +61,11 @@ import java.util.concurrent.TimeUnit;
class PollingWatchService
extends AbstractWatchService
{
// Wait between polling thread creation and first poll (seconds)
private static final int POLLING_INIT_DELAY = 1;
// Default time between polls (seconds)
private static final int DEFAULT_POLLING_INTERVAL = 2;
// map of registrations
private final Map<Object, PollingWatchKey> map = new HashMap<>();
@ -115,7 +120,7 @@ class PollingWatchService
throw new IllegalArgumentException("No events to register");
// Extended modifiers may be used to specify the sensitivity level
int sensitivity = 10;
int sensitivity = DEFAULT_POLLING_INTERVAL;
if (modifiers.length > 0) {
for (WatchEvent.Modifier modifier: modifiers) {
if (modifier == null)
@ -247,6 +252,7 @@ class PollingWatchService
* directory and queue keys when entries are added, modified, or deleted.
*/
private class PollingWatchKey extends AbstractWatchKey {
private final Object fileKey;
// current event set
@ -305,10 +311,10 @@ class PollingWatchService
// update the events
this.events = events;
// create the periodic task
// create the periodic task with initialDelay set to the specified constant
Runnable thunk = new Runnable() { public void run() { poll(); }};
this.poller = scheduledExecutor
.scheduleAtFixedRate(thunk, period, period, TimeUnit.SECONDS);
.scheduleAtFixedRate(thunk, POLLING_INIT_DELAY, period, TimeUnit.SECONDS);
}
}