首页 > 技术文章 > Java 异步处理 三种实现

RuMengkai 2018-12-12 15:11 原文

        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 {

    }
}

  

推荐阅读