Samples JDK
Sample.java
1 package com.freemindcafe.concurrency.sample8;
2 
3 import java.util.concurrent.Executors;
4 import java.util.concurrent.ScheduledExecutorService;
5 import java.util.concurrent.TimeUnit;
6 
7 public class Sample {
8 
9  //ScheduledExecutorService's thread don't terminate by itself
10  //It is a non daemon thread and will prevent the jvm from existing
11  public static void main(String[] args) {
12  ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
13  service.schedule(()->{System.out.println("hi");}, 5, TimeUnit.SECONDS);
14  service.shutdown();
15  System.out.println("after thread pool shutdown");
16 
17  }
18 
19 }