Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sandeepnegi1996/94f9ef104219fac0be8017f8aa5c7700 to your computer and use it in GitHub Desktop.
Save sandeepnegi1996/94f9ef104219fac0be8017f8aa5c7700 to your computer and use it in GitHub Desktop.
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