try { CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> { //业务代码 return 200; } catch (Exception e) { e.printStackTrace(); return 500; } }, ThreadPoolManager.THREAD_POOL_EXECUTOR); Integer resultCode = future.get(1000, TimeUnit.MILLISECONDS); if (500 == resultCode) { throw new Exception( "操作超时!"); } } catch (Exception e) { log.error(" 数据插入失败:{}", "xxx"); e.printStackTrace(); throw new Exception( "操作超时!"); }