1 package com.nexuiz.demorecorder.application;
\r
4 import java.util.ArrayList;
\r
5 import java.util.List;
\r
6 import java.util.concurrent.ArrayBlockingQueue;
\r
7 import java.util.concurrent.ThreadPoolExecutor;
\r
8 import java.util.concurrent.TimeUnit;
\r
10 import com.nexuiz.demorecorder.application.jobs.RecordJob;
\r
12 public class RecorderJobPoolExecutor {
\r
14 private int poolSize = 1;
\r
15 private int maxPoolSize = 1;
\r
16 private long keepAliveTime = 10;
\r
17 private ThreadPoolExecutor threadPool = null;
\r
18 private ArrayBlockingQueue<Runnable> queue = null;
\r
20 public RecorderJobPoolExecutor() {
\r
21 queue = new ArrayBlockingQueue<Runnable>(99999);
\r
22 threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, queue);
\r
25 public void runJob(Runnable task) {
\r
26 threadPool.execute(task);
\r
29 public void clearUnfinishedJobs() {
\r
30 threadPool.getQueue().clear();
\r
33 public void shutDown() {
\r
34 threadPool.shutdownNow();
\r
37 public synchronized List<RecordJob> getJobList() {
\r
38 List<RecordJob> list = new ArrayList<RecordJob>();
\r
39 for (Runnable job : this.queue) {
\r
41 RecordJob j = (RecordJob)job;
\r
43 } catch (ClassCastException e) {}
\r