異步編程的處理方式
1.@Async 注解,加上這個(gè)注解就行了,注意加到具體實(shí)現(xiàn)上。即
@Async
@Override
2. 使用 CompletableFuture
CompletableFuture.runAsync(() -> { // JSONObject ret = null; try { payableOrderService.pushSapAsync(po_push_payable, map); interfaceLogPO.setIsSuccess(1); // interfaceLogPO.setResponse(ret.toJSONString()); } catch (Exception e) { interfaceLogPO.setIsSuccess(0); interfaceLogPO.setResponse(e.getMessage()); throw e; } finally { try { interfaceLogClient.saveInterfaceLog(interfaceLogPO); } catch (Exception e) { } } });
3.ExecutorService.submit()
對(duì)于java來說,以上三種異步編程都是使用線程池去實(shí)現(xiàn)的,因此可以大致認(rèn)為異步就是多線程的一種情況。無非是兩個(gè)線程。
下班記得打卡

浙公網(wǎng)安備 33010602011771號(hào)