Do these nested ExecutorServices make sense in Java?

Viewed 51

I stumbled across some legacy code and found this expression in connection with some async database handling:

ExecutorService SERVICE = Executors.newCachedThreadPool();

SERVICE.execute(() - > {
  try {
    SERVICE.execute(new Runnable() {
      @Override
      public void run() {
        // do stuff
      }
    });
  } catch (Exception e) {
    e.printStackTrace();
  }
});

My question is, is there any reason for calling execute() twice on the ExecutorService? Wouldn't it be easier to just run:

  try {
    SERVICE.execute(new Runnable() {
      @Override
      public void run() {
        // do stuff
      }
    });
  } catch (Exception e) {
    e.printStackTrace();
  }
0 Answers
Related