zoukankan      html  css  js  c++  java
  • ExecutionException相关

    在项目中发现一个情况,线程中一段很快的代码突然变得非常的慢,打log调试发现顺序代码运行到一半就退出。最后发现原因来自于如下代码段:

    private <T> T executeAndWait(Callable<T> callable) {
    	FutureTask<T> task = new FutureTask<T>(callable);
    	mMainHandler.sendMessage(
    			mMainHandler.obtainMessage(MSG_RUN_OBJECT, task));
    	try {
    		return task.get();
    	} catch (InterruptedException e) {
    		Log.w(TAG,"executeAndWait:  "+e);
    	} catch (ExecutionException e) {
    		//throw new RuntimeException(e);
    		Log.w(TAG,"executeAndWait:  "+e);
    	}
    	
    	return null;
    }
    

    代码运行到一半异常退出只有一个情况,那就是线程异常退出了,所以我找到了线程启动的地方,发现这里有一个陌生的ExecutionException,打出相应的log,果然是这里catch了线程异常

    W/AllItemDataLoader(19548): executeAndWait:  java.util.concurrent.ExecutionException: java.lang.NullPointerException: Attempt to read from field 'com.android.gallery3d.glrenderer.BitmapTexture com.android.gallery3d.vivo.AllItemSldingWindow$SlotEntry.labelTexture' on a null object reference
    

     该异常的定义如下:

    Exception thrown when attempting to retrieve the result of a task that aborted by throwing an exception
    

      task本身崩溃抛出的异常,也就是说上述代码中Callable参数任务中抛出的任何异常都会在这里捕获抛出ExecutionException异常。

    因此解决这个异常的办法就是解决task中自身的异常,这里是空指针异常,找到task中可能调用到SlotEntry.labtexture的地方调试是否有空指针的情况即可。

  • 相关阅读:
    UniConnector平台
    UniConnector平台
    UniChat 社交IM 集成环信
    移动办公OA App 工作流审批
    netcore 部署Docker
    .net core 腾讯短信发送
    Linux error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol
    Linux nginx 自启动
    Linux 配置、问题
    Swagger自定义默认首页
  • 原文地址:https://www.cnblogs.com/fordreamxin/p/5210083.html
Copyright © 2011-2022 走看看