Java newSingleThreadExecutor example
GIAN Tutorials
8:20 AM
Executor’s newSingleThreadExecutor factory method : This method returns thread pool executor which executes one task at a time.If you have submitted n task to executors, it will execute it one by one.If this thread gets interrupted then a new thread will be created for executing the tasks. Syntax: 1 2 3 ExecutorService executorService = Executors . newSingleThreadExecutor ( ) ; Java newSingleThreadExecutor example: Let’s create a very simple example. Step 1: Create a Runnable task named “LoopTask.java”. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 package org . arpit . java2blog ; public class LoopTask implements Runnable { private String loopTaskName ; public LoopTask ( String loopTaskName ) { super ( ) ; this . loopTaskName = loopTaskName ; } @ Override public ...