子线程任务发生异常,主线程事务如何回滚?
Java貌似可以这样简单写 ExecutorService executorService = Executors.newFixedThreadPool(5); Future submit = executorService.submit(new Callable() { @Override public Object call() throws Exception { int a = 1 / 0; return ''; } }); try { Object object = submit.get(); System.out.println('正常执行'); } catch (Exception e) { System.out.println('手动回滚事务'); e.printStackTrace(); }
赞0
踩0