I am trying to make ThreadPoolExecutor with priority. Therefore I define
private static ThreadPoolExecutor threadpool = new ThreadPoolExecutor(30, MAXPOOL, MAXPOOL, TimeUnit.SECONDS, queue, new mThreadFactory());
So, the key is a link to the queue. But when I declare:
static PriorityBlockingQueue<mDownloadThread> queue=new PriorityBlockingQueue<mDownloadThread>(MAXPOOL,new DownloadThreadComparator());
The compiler throws an error in the first line: The ThreadPoolExecutor constructor (int, int, int, TimeUnit, PriorityBlockingQueue, FileAccess.mThreadFactory) has undefined with one quick value: the change type is 'queue' to BlockingQueue. Can you help me understand what the problem is?
thanks
Additional Information:
For comparison runnables, I implement the following class
class mDownloadThread implements Runnable{ private Runnable mRunnable; private int priority; mDownloadThread(Runnable runnable){ mRunnable=runnable; } @Override public void run() { mRunnable.run(); } public int getPriority() { return priority; } public void setPriority(int priority) { this.priority = priority; } }
Comparator:
class DownloadThreadComparator implements Comparator<mDownloadThread>{ @Override public int compare(mDownloadThread arg0, mDownloadThread arg1) { if (arg0==null && arg1==null){ return 0; } else if (arg0==null){ return -1; } else if (arg1==null){ return 1; } return arg0.getPriority()-arg1.getPriority(); } }
Addev source share