Atitit 流水線子線程異常處理
Atitit 流水線子線程異常處理
?
?
1.1. 大概原理是 FutureTask排除異常 FutureTask.get ??can throw ExecutionException,can catch this ex... 1
1.2. code 1
?
?
1.1.?大概原理是 FutureTaskt throw 異常 FutureTask.get ??can throw ExecutionException,can catch this ex...
?
Throwable?cause?=?e.getCause();?
if(cause.getMessage().contains("sub task err"))
{
RunEx?re=(RunEx)?cause;
System.out.println(JSON.toJSONString(?re.returnObj));
System.out.println();
}else
ExUtil.throwExV2(e);
?
?
1.2.?code
?
package?com.cnhis.cloudhealth.clinical.clidoctor.clisendadvice.bo;
?
import?java.util.Map;
import?java.util.concurrent.Callable;
import?java.util.concurrent.ExecutionException;
import?java.util.concurrent.FutureTask;
?
import?com.alibaba.fastjson.JSON;
import?com.cnhis.cloudhealth.commons.util.oplogutil.AsynUtil;
import?com.cnhis.cloudhealth.util.ExUtil;
import?com.cnhis.cloudhealth.util.RunEx;
import?com.google.common.collect.Maps;
?
public?class?FuturetaskExTest?{
?
public?static?void?main(String[]?args)?{
// TODO?Auto-generated method stub
FutureTask?tsk=?subtask();
System.out.println("--");
try?{
tsk.get();
}?catch?(InterruptedException?e)?{
// TODO?Auto-generated catch block
e.printStackTrace();
}?catch?(ExecutionException?e)?{
Throwable?cause?=?e.getCause();?
if(cause.getMessage().contains("sub task err"))
{
RunEx?re=(RunEx)?cause;
System.out.println(JSON.toJSONString(?re.returnObj));
System.out.println();
}else
ExUtil.throwExV2(e);
}
//System.out.println("--");
?
}
?
public?static?FutureTask?subtask()?{
FutureTask
?
??@Override
??public?Object?call()???{?
??System.out.println("--e in sub thread");
??
??if("a".equals("a"))
??{
??Map?m=Maps.newConcurrentMap();m.put("k",?"vv");
???throw?new?RunEx("sub task err",m);
???
??}
??return?"err";
??}
??})?;
??
???AsynUtil.execMeth_Ays(?FutureTask_updateCviBdj,"");
return?FutureTask_updateCviBdj;
}
?
}
?