FindBugs:RV_RETURN_VALUE_IGNORED_BAD_PRACTICE 使用 ExecutorService

huangapple go评论82阅读模式
英文:

Findbugs: RV_RETURN_VALUE_IGNORED_BAD_PRACTICE using ExecutorService

问题

I'm using Findbugs and I'm getting the RV_RETURN_VALUE_IGNORED_BAD_PRACTICE next error, this is my code:

ExecutorService executor = Executors.newSingleThreadExecutor();
try {
executor.submit(() -> {
LOGGER.info(
".............",
Some Code.....
});
executor.shutdown();
executor.awaitTermination(5, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
LOGGER.info(".........);
}
finally {
if (!executor.isTerminated()) {
LOGGER.info(.....);
}
executor.shutdownNow();
LOGGER.info(.........);
}

The issue is in the line: executor.submit(() -> {

Any ideas?

英文:

I'm using Findbugs and I'm getting the RV_RETURN_VALUE_IGNORED_BAD_PRACTICE next error, this is my code:

ExecutorService executor = Executors.newSingleThreadExecutor();
      try {
        executor.submit(() -> {
          LOGGER.info(
              ".............",
              Some Code.....
        });
        executor.shutdown();
        executor.awaitTermination(5, TimeUnit.SECONDS);
      }
      catch (InterruptedException e) {
        LOGGER.info(".........);
      }
      finally {
        if (!executor.isTerminated()) {
          LOGGER.info(.....);
        }
        executor.shutdownNow();
        LOGGER.info(.........);
      }

The issue is in the line: executor.submit(() -> {

Any ideas?

答案1

得分: 4

如果您真的不关心执行结果,应该使用 executor.execute(()-> {LOGGER.info(...)});

英文:

If you really don't care about the result of the execution, you should use executor.execute(()-> {LOGGER.info(...)}); instead.

huangapple
  • 本文由 发表于 2020年8月6日 02:44:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63271651.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定