class1
public class MyExecutor {
private ExecutorService executor = Executors.newCachedThreadPool() ;
public void fun() throws Exception {
executor.submit(new Runnable(){
@override
public void run() {
try {
//要执行的业务代码
Thread.sleep(10000);
System.out.print("----------");
}catch(Exception e) {
throw new RuntimeException("ERRO!");
}
}
});
}
}
class2
public class Demo{
public static void main(String[] args) {
MyExecutor myExecutor = new MyExecutor();
try {
myExecutor.fun();
System.our.print("========");
}catch(Exception e) {
throw new RuntimeException("RUN_ERRO");
}
}
}