package com.gkhy.assess.common.utils;
|
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
|
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.Future;
|
|
/**
|
* 线程相关工具类
|
*/
|
public class Threads {
|
private static final Logger logger = LoggerFactory.getLogger(Threads.class);
|
public static void printException(Runnable r,Throwable t){
|
if(t==null && r instanceof Future<?>){
|
try {
|
Future<?> future= (Future<?>) r;
|
if(future.isDone()) {
|
future.get();
|
}
|
} catch (CancellationException e){
|
t=e;
|
} catch (ExecutionException e) {
|
t=e.getCause();
|
}catch (InterruptedException e) {
|
Thread.currentThread().interrupt();
|
}
|
}
|
if(t!=null){
|
logger.error(t.getMessage(),t);
|
}
|
}
|
}
|