Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Last active December 16, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warmwaffles/5496037 to your computer and use it in GitHub Desktop.
Save warmwaffles/5496037 to your computer and use it in GitHub Desktop.
package net.warmwaffles;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class Scheduler {
private static Scheduler instance;
private ThreadPoolExecutor executor;
private LinkedBlockingQueue<Runnable> queue;
public Scheduler() {
int processors = Runtime.getRuntime().availableProcessors();
queue = new LinkedBlockingQueue<Runnable>();
executor = new ThreadPoolExecutor(processors, 10, 10, TimeUnit.SECONDS, queue);
}
public void schedule(Runnable runnable) {
executor.execute(runnable);
}
public static void scheduleTask(Runnable runnable) {
getInstance().schedule(runnable);
}
public static Scheduler getInstance() {
if (instance == null) {
instance = new Scheduler();
}
return instance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment