Skip to content

Commit

Permalink
Replace timer with scheduled executor service
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-gh committed Mar 19, 2016
1 parent c6daac0 commit 9022273
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import net.minecrell.serverlistplus.core.util.Wrapper;

import java.util.TimerTask;
import java.util.concurrent.ScheduledFuture;

public final class ScheduledTimerTask extends Wrapper<TimerTask> implements ScheduledTask {
public final class ScheduledFutureTask extends Wrapper<ScheduledFuture<?>> implements ScheduledTask {

public ScheduledTimerTask(TimerTask handle) {
public ScheduledFutureTask(ScheduledFuture<?> handle) {
super(handle);
}

@Override
public void cancel() {
this.handle.cancel();
this.handle.cancel(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import net.minecrell.serverlistplus.server.status.StatusPingResponse;
import net.minecrell.serverlistplus.server.status.UserProfile;
import net.minecrell.serverlistplus.server.util.FormattingCodes;
import net.minecrell.serverlistplus.server.util.RunnableTimerTask;

import java.awt.image.BufferedImage;
import java.net.InetSocketAddress;
Expand All @@ -50,8 +49,8 @@
import java.util.Locale;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

Expand All @@ -65,7 +64,7 @@ public final class ServerListPlusServer implements ServerListPlusPlugin {

private final NetworkManager network;

private final Timer timer = new Timer(true);
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();

private boolean started;

Expand Down Expand Up @@ -343,14 +342,12 @@ public LoadingCache<FaviconSource, Optional<String>> getFaviconCache() {

@Override
public void runAsync(Runnable task) {
this.timer.schedule(new RunnableTimerTask(task), 0); // TODO: Remove
this.scheduler.execute(task);
}

@Override
public ScheduledTask scheduleAsync(Runnable task, long repeat, TimeUnit unit) {
TimerTask timerTask = new RunnableTimerTask(task);
this.timer.scheduleAtFixedRate(timerTask, 0, unit.toMillis(repeat));
return new ScheduledTimerTask(timerTask);
return new ScheduledFutureTask(this.scheduler.scheduleAtFixedRate(task, 0, repeat, unit));
}

@Override
Expand Down

This file was deleted.

0 comments on commit 9022273

Please sign in to comment.