Skip to content
Snippets Groups Projects
Commit 6c4c0926 authored by akwizgran's avatar akwizgran
Browse files

Randomise initial polling intervals to spread out connection attempts.

parent db475577
No related branches found
No related tags found
No related merge requests found
...@@ -36,14 +36,16 @@ class PollerImpl implements Poller, Runnable { ...@@ -36,14 +36,16 @@ class PollerImpl implements Poller, Runnable {
} }
public synchronized void start(Collection<Plugin> plugins) { public synchronized void start(Collection<Plugin> plugins) {
for(Plugin plugin : plugins) schedule(plugin); for(Plugin plugin : plugins) schedule(plugin, true);
new Thread(this, "Poller").start(); new Thread(this, "Poller").start();
} }
private synchronized void schedule(Plugin plugin) { private synchronized void schedule(Plugin plugin, boolean randomise) {
if(plugin.shouldPoll()) { if(plugin.shouldPoll()) {
long now = clock.currentTimeMillis(); long now = clock.currentTimeMillis();
long interval = plugin.getPollingInterval(); long interval = plugin.getPollingInterval();
// Randomise intervals at startup to spread out connection attempts
if(randomise) interval = (long) (interval * Math.random());
pollTimes.add(new PollTime(now + interval, plugin)); pollTimes.add(new PollTime(now + interval, plugin));
} }
} }
...@@ -74,7 +76,7 @@ class PollerImpl implements Poller, Runnable { ...@@ -74,7 +76,7 @@ class PollerImpl implements Poller, Runnable {
p.plugin.poll(connected); p.plugin.poll(connected);
} }
}); });
schedule(p.plugin); schedule(p.plugin, false);
} else { } else {
try { try {
wait(p.time - now); wait(p.time - now);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment