Skip to content

Commit

Permalink
Added pool of executors instead of spawning one threads.
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka committed Mar 4, 2016
1 parent 06dce67 commit 6aa1205
Showing 1 changed file with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -746,34 +747,20 @@ Response createChange(String projectId, String zoneName, Change change, String..
}

/**
* Applies change. Uses a new thread which applies the change only if DELAY_CHANGE is > 0.
* Applies change. Uses a different pooled thread which applies the change only if {@code
* delayChange} is > 0.
*/
private Thread invokeChange(final String projectId, final String zoneName,
private void invokeChange(final String projectId, final String zoneName,
final String changeId) {
if (delayChange > 0) {
EXECUTORS.scheduleWithFixedDelay(new Runnable() {
EXECUTORS.schedule(new Runnable() {
@Override
public void run() {
applyExistingChange(projectId, zoneName, changeId);
}
}, delayChange, )
Thread thread = new Thread() {
@Override
public void run() {
try {
Thread.sleep(delayChange); // simulate delayed execution
} catch (InterruptedException ex) {
log.log(Level.WARNING, "Thread was interrupted while sleeping.", ex);
}
// start applying the changes
applyExistingChange(projectId, zoneName, changeId);
}
};
thread.start();
return thread;
}, delayChange, TimeUnit.MILLISECONDS);
} else {
applyExistingChange(projectId, zoneName, changeId);
return null;
}
}

Expand Down

0 comments on commit 6aa1205

Please sign in to comment.