Springboot Mongodb 异步方法后插入出现 MongoInterruptedException

2020-05-14 00:03:16 +08:00
 stephCurry

异常信息:

ERROR [task-2] org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler [handleUncaughtException#39] : Unexpected exception occurred invoking async method: public void org.cert.securityanalyzer.core.ScanEngine.run(java.util.List)
org.springframework.data.mongodb.UncategorizedMongoDbException: Interrupted acquiring a permit to retrieve an item from the pool ; nested exception is com.mongodb.MongoInterruptedException: Interrupted acquiring a permit to retrieve an item from the pool 
    at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:138)
    at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2783)
    at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:546)
    at org.springframework.data.mongodb.core.MongoTemplate.insertDocument(MongoTemplate.java:1433)
    at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:1243)


伪代码如下

@Async
public void scan(List<File> files) {
  files.foreach(f -> {
    try{
      scanSevice.scan(file);
      file.setSuccess(true);
    } catch (Exception e){
        file.setSuccess(false);
    }

    mongoTemplate.insert(file);
   })

Google 了许多,有的说是因为其他线程 interrupted 导致,参见这篇 jira,我所依赖方法是多线程的,引用别人的 jar,属于我这边不可控的,的确,看到引用那边如果它的多线程出了异常,我这 mongo 就插不进去,如果没错误的话就能插进去,但是这是 mongo 的坑吧,直接测试FilsUtils.writeStringToFile是没问题的。


依赖的方法异常片段:

ERROR [Thread-74] heros.solver.CountingThreadPoolExecutor [afterExecute#64] : Worker thread execution failed: Opcode: IGET_BOOLEAN_QUICK @ 0x21
java.lang.IllegalArgumentException: Opcode: IGET_BOOLEAN_QUICK @ 0x21
	at soot.dexpler.instructions.InstructionFactory.fromOpcode(InstructionFactory.java:381)
	at soot.dexpler.instructions.InstructionFactory.fromInstruction(InstructionFactory.java:48)
	at soot.dexpler.DexBody.extractDexInstructions(DexBody.java:242)
	at soot.dexpler.DexBody.<init>(DexBody.java:208)
	at soot.dexpler.DexMethod$1.getBody(DexMethod.java:118)
	at soot.SootMethod.retrieveActiveBody(SootMethod.java:402)
	at soot.PackManager$3.run(PackManager.java:1293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

已尝试的方法,但没用。。。


但是遗憾还不行。。。 大佬们是否遇到过此类情况?或者有什么建议方法?尽量不改现有框架把。。

3121 次点击
所在节点    Java
1 条回复
stephCurry
2020-05-14 00:06:05 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/671426

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX