We would like to know how to create new Single Thread Executor.
import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; //from w w w .j av a2 s .c o m public class Main implements Runnable { public void run() { System.out.println("produces " + idSequence.incrementAndGet()); } public static void main(String[] args) { for (int i = 0; i < 200; i++) Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate( new Main(), 1, 10, TimeUnit.SECONDS); } private static final AtomicLong idSequence = new AtomicLong(0); }
The code above generates the following result.