Asynchronous server performance optimization of queries turn sync

I wrote an article before I met shared a BUG as a performance optimization occurs at work: asynchronous query turn synchrotron BUG share redis service implementation .

Recently encountered a similar task, there are some multi-query interfaces are suitable for this turn asynchronous query optimization synchronized, so share the program performance optimization server interface used.

Personally I think that this program is suitable query interface (involving writing data separate clause) have about the following characteristics:

  • Multiple queries
  • Query longer time
  • Return result does not depend on one another

Pseudo-code as follows:

    @Override
    public void doExecute(Map<String, Object> dataMap) {
        doSomething(dataMap);
        CountDownLatch countDownLatch = new CountDownLatch(3);
        teacherPadAsyncService.do1(dataMap, countDownLatch, params);
        teacherPadAsyncService.do2(dataMap, countDownLatch, params);
        teacherPadAsyncService.do3(dataMap, countDownLatch, params);
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            logger.error("异步处理线程异常", e);
        }
    }复制代码

Implementation is very simple, by spring of @Asyncannotations, where the need to modify some configuration, not repeat them, pay attention to thread safety.

    @Async
    public void do1(Map<String, Object> dataMap, CountDownLatch countDownLatch, Params params) {
        try {
            dosomething(dataMap, params);
        } catch (Exception e) {
            dosomething();
        } finally {
            countDownLatch.countDown();
        }
    }复制代码

This could be considered a routine optimization program, have the opportunity to share with other optimization.

  • Solemnly declare : The article first appeared in public No. "FunTester", prohibit third parties (except Tencent cloud) reproduce, publish.

Technology Featured articles

Non-technical Selected Articles

Guess you like

Origin juejin.im/post/5e425dcb51882549380c80a3