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 {

    }
}

  

posted @ 2018-12-12 15:11  茹孟凯  阅读(5596)  评论(0编辑  收藏  举报