Last active
December 16, 2015 20:59
-
-
Save warmwaffles/5496037 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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