Java 异步处理 三种实现
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 {
}
}

浙公网安备 33010602011771号