mybatis-3 icon indicating copy to clipboard operation
mybatis-3 copied to clipboard

Multithreading executes mapper query methods

Open leein opened this issue 4 years ago • 1 comments

user completableFutures[] executes mapper query methods.But appear org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: java.lang.ArithmeticException: / by zero

How can I solve it?

for (Map.Entry<Integer, String> entry : hashMap.entrySet()) { final String[] params1=entry.getValue().split(","); final Integer params2=entry.getKey(); completableFutures.add(CompletableFuture.supplyAsync(()->{ for(int i=0;i< params1.length;i++){ int result=0; if (type % 2 != 0) { result = testMapper.getCountOne(params2, Long.valueOf(params1[i])); }else{ result = testMapper.getCountTwo(params2, Long.valueOf(params1[i])); } String key = params2+ "-" + params1[i]; hashMapList.put(key,result); } return null; })); } CompletableFuture[] futuresArray = new CompletableFuture[completableFutures.size()]; CompletableFuture.allOf(completableFutures.toArray(futuresArray)).join();

Integer getCountOne(@Param("pone") int pone, @Param("ptwo") long ptwo);

Integer getCountTwo(@Param("pone") int pone, @Param("ptwo") long ptwo);

leein avatar Apr 17 '22 12:04 leein

Hello @leein ,

It does not seem like a MyBatis issue. Does the same error occur if you don't use CompletableFuture? If it does, please post the full stack trace. If it does not, there may be some kind of logical error in your code.

harawata avatar Apr 30 '22 21:04 harawata

No response. Closing.

harawata avatar Mar 08 '23 22:03 harawata