在线程池中执行runnable时,给定线程不存在

时间:2012-08-27 15:27:22

标签: java android multithreading thread-safety

我在应用中遇到以下问题: 为了在后台执行某些操作,我声明了一个ThreadPoolExecutor

private static ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5, 100,
         100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100));

然后我运行任务

poolExecutor.execute (new Runnable() {
        public void run() {
            Process.getThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
             ...
        }

但该应用程序在此时崩溃说:

java.lang.IllegalArgumentException: Given thread does not exist

代码问题是什么?感谢

1 个答案:

答案 0 :(得分:1)

您可能需要setThreadPriority而不是getThreadPriority

poolExecutor.execute (new Runnable() {
    public void run() {
        Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
         ...
    }