我在这里和其他网站上阅读了许多帖子,但找不到创建错误的问题:
我使用 AsyncTask 因为我想在执行之前和之后轻松操作 UI 线程。
在 doInBackground 中,我创建了一个 ThreadPoolExecutor 并执行 Runnables。
如果我只使用 Executor 执行 1 个 Runnable,则没有问题,但如果我执行另一个 Runnable,则会出现以下错误:
06-26 18:00:42.288: A/libc(25073): Fatal signal 11 (SIGSEGV) at 0x7f486162 (code=1), thread 25106 (pool-1-thread-2)
06-26 18:00:42.304: D/dalvikvm(25073): GC_CONCURRENT freed 119K, 2% free 8908K/9056K, paused 4ms+4ms, total 45ms
06-26 18:00:42.327: I/System.out(25073): In Check All with Prefix: a and Length: 4
06-26 18:00:42.390: I/DEBUG(126): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-26 18:00:42.390: I/DEBUG(126): Build fingerprint: 'google/yakju/maguro:4.2.2/JDQ39/573038:user/release-keys'
06-26 18:00:42.390: I/DEBUG(126): Revision: '9'
06-26 18:00:42.390: I/DEBUG(126): pid: 25073, tid: 25106, name: pool-1-thread-2 >>> de.uni_duesseldorf.cn.distributed_computing2 <<<
06-26 18:00:42.390: I/DEBUG(126): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 7f486162
...
06-26 18:00:42.538: I/DEBUG(126): memory map around fault addr 7f486162:
06-26 18:00:42.538: I/DEBUG(126): 60292000-60391000
06-26 18:00:42.538: I/DEBUG(126): (no map for address)
06-26 18:00:42.538: I/DEBUG(126): bed14000-bed35000 [stack]
我这样设置 ThreadPoolExecutor:
// numberOfPackages: Number of Runnables to be executed
public void initializeThreadPoolExecutor (int numberOfPackages)
{
int corePoolSize = Runtime.getRuntime().availableProcessors();
int maxPoolSize = numberOfPackages;
long keepAliveTime = 60;
final BlockingQueue workingQueue = new LinkedBlockingQueue();
executor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, workingQueue);
}
我不知道为什么在启动第二个线程时它会失败。
也许内存泄漏?
任何帮助表示赞赏。
提前致谢