Multithreading executes mapper query methods
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);
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.
No response. Closing.