Created
June 4, 2022 07:15
-
-
Save sandeepnegi1996/94f9ef104219fac0be8017f8aa5c7700 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.vertx.example; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
public class ExecutorExample { | |
public static void main(String[] args) { | |
System.out.println("Inside : " + Thread.currentThread().getName()); | |
System.out.println("Creating Executor Service..."); | |
ExecutorService executorService= Executors.newSingleThreadExecutor(); | |
System.out.println("Creating Runnable..."); | |
Runnable runnable1 = ( ) -> { | |
try { | |
Thread.sleep(3000); | |
} catch (InterruptedException e) { | |
throw new RuntimeException(e); | |
} | |
System.out.println("Inside : " + Thread.currentThread().getName()); | |
}; | |
System.out.println("Creating Runnable 2 Example ...."); | |
Runnable runnable2 = ( ) -> { | |
System.out.println("Inside : "+ Thread.currentThread().getName()); | |
}; | |
System.out.println("submitting runnable 1"); | |
executorService.submit(runnable1); | |
System.out.println("Submitting runnable 2"); | |
executorService.submit(runnable2); | |
executorService.shutdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment