FindBugs:RV_RETURN_VALUE_IGNORED_BAD_PRACTICE 使用 ExecutorService

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

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:

  1. ExecutorService executor = Executors.newSingleThreadExecutor();
  2. try {
  3. executor.submit(() -> {
  4. LOGGER.info(
  5. ".............",
  6. Some Code.....
  7. });
  8. executor.shutdown();
  9. executor.awaitTermination(5, TimeUnit.SECONDS);
  10. }
  11. catch (InterruptedException e) {
  12. LOGGER.info(".........);
  13. }
  14. finally {
  15. if (!executor.isTerminated()) {
  16. LOGGER.info(.....);
  17. }
  18. executor.shutdownNow();
  19. LOGGER.info(.........);
  20. }

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:

确定