0

我在这里和其他网站上阅读了许多帖子,但找不到创建错误的问题:
我使用 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);
}

我不知道为什么在启动第二个线程时它会失败。
也许内存泄漏?

任何帮助表示赞赏。
提前致谢

4

4 回答 4

2

我遇到了同样的错误,但我发现发生崩溃是因为我将位图存储在我的对象中,而 Android 无法很好地处理位图。我通过将位图转换为 Base64 字符串将数据类型从位图更改为字符串,从而解决了致命问题。这可能会帮助某人。

于 2017-09-25T11:05:14.493 回答
1

如果您没有执行您自己的任何本机代码(或来自您添加的第三方库),那么您在此设备上的 Android 副本中遇到了一些错误。虽然本机代码中的错误可能会导致SIGSEGV,但您在 Java 中所做的任何事情都不应该发生。

如果您可以在多个制造商的多个设备/模拟器上重现此问题,那么问题可能出在 Android 本身。如果问题仅出现在单个设备上,则很可能是该设备独有的错误。

于 2013-06-26T16:20:07.273 回答
0

RejectionExecutionHandler处理它,只需 在下面的实例化中
添加另一个参数( )new ThreadPoolExecutor.DiscardPolicy()ThreadPoolExecutor

executor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, workingQueue,new ThreadPoolExecutor.DiscardPolicy());
于 2013-06-26T16:28:31.570 回答
0

I found the cause of this problem.

I was creating the working queue as a local variable in initializeThreadPoolExecutor(). After exiting the method, it seems the working queue was deleted by the Java Garbage Collector, so it was inaccessible when I wanted to add another Task to the queue.

To fix the problem I created a global variable workingQueue and used this when initializing my ThreadPoolExecutor.

Thanks for the Help.

于 2013-06-29T14:15:35.400 回答