JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label newSingleThreadExecutor. Show all posts
Showing posts with label newSingleThreadExecutor. Show all posts

Java newSingleThreadExecutor example

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 ...

.