public class ScheduledExecutorServiceDemo {

  public static void main(String[] args) throws ExecutionException, InterruptedException {

    BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build();
    ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, threadFactory);

    ScheduledFuture scheduledFuture = executorService.schedule((Callable) () -> {
      System.out.println("Executed!");
      return "Called!";
    }, 5, TimeUnit.SECONDS);

    Object result = scheduledFuture.get();
    System.out.println("result = " + result);

  }
}

参考资料