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 @Async
annotations, 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
- Linux performance monitoring software netdata Chinese Version
- Performance testing framework Third Edition
- How delightful performance testing Linux command line interface
- Brain HTTP illustrated in FIG.
- The swagger document automatically become the test code
- Selenium 4.0 Alpha Update Log
- Selenium 4.0 Alpha practice updates
- How unified interface testing functionality, automation and performance test cases