| 27 | import jnode.logger.Logger; |
| 28 | |
| 29 | public class ThreadPool { |
| 30 | private static ThreadPool self; |
| 31 | private static final Logger logger = Logger.getLogger(ThreadPool.class); |
| 32 | private ThreadPoolExecutor executor; |
| 33 | |
| 34 | public ThreadPool(int numThreads) { |
| 35 | executor = new ThreadPoolExecutor(numThreads, (int) (numThreads * 1.5), |
| 36 | 30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); |
| 37 | |
| 38 | logger.l3("Thread pool (" + numThreads + " threads) started"); |
| 39 | self = this; |
| 40 | } |
| 41 | |
| 42 | public static void execute(Runnable r) { |
| 43 | if (self != null) { |
| 44 | self.executor.execute(r); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | public static boolean isBusy() { |
| 49 | if (self != null) { |
| 50 | return self.executor.getQueue().size() > self.executor |
| 51 | .getMaximumPoolSize(); |
| 52 | } |
| 53 | return true; |
| 54 | } |
| 55 | } |