Java 异步处理 三种实现

时间:2024-12-20 16:08:08
        new Thread((new Runnable() {
@Override
public void run() {
// 批量同步数据
try {
logger.info("^^^^^^^^^^^^^^^^^ sync start ^^^^^^^^^^^^^^^^^ "); logger.info("^^^^^^^^^^^^^^^^^ sync end ^^^^^^^^^^^^^^^^^ ");
} catch (IOException e) {
LogUtils2.error("", e);
}
}
})).start();

 

 private ExecutorService executor = Executors.newFixedThreadPool(1);

 executor.submit(new Runnable() {
@Override
public void run() {
// 批量同步数据
try {
logger.info("^^^^^^^^^^^^^^^^^ sync weinxi data start ^^^^^^^^^^^^^^^^^ ");
weiXinUsersService.batchSaveHandle();
logger.info("^^^^^^^^^^^^^^^^^ sync weinxi data end ^^^^^^^^^^^^^^^^^ ");
} catch (IOException e) {
LogUtils2.error("", e);
}
}
});

  spring boot:

@EnableAsync
public class WeiXinUsersService extends BaseGongfuService { @Async
public void batchSaveHandle() throws IOException { }
}

  

相关文章