Skip to content

Instantly share code, notes, and snippets.

class Tasks {
public static void main(String[] args) {
ExecutorService executorService = Executors.newFixedThreadPool(3);
executorService.submit(new Task1());
executorService.submit(new Task2());
executorService.submit(new Task3());
executorService.shutdown();
}
}
@sne007
sne007 / Tasks.java
Last active September 24, 2020 05:39
class Tasks {
public static void main(String[] args) {
Tasks t = new Tasks();
Task1 t1 = new Task1();
Task2 t2 = new Task2();
Task3 t3 = new Task3();
t1.start();
t2.start();
t3.start();
class ThreadForT1 implements Runnable {
public void run() {
System.out.println("Thread for T1 is running in thread " + Thread.currentThread().getName());
}
public static void main(String[] args) {
ThreadForT1 t = new ThreadForT1();
t.run();
}
}
@sne007
sne007 / gist:4184f458007ed3e06bc923caea0a7c3d
Created September 23, 2020 16:23
RunnableThread.java
class ThreadForT1 implements Runnable {
public void run() {
System.out.println("Thread for T1 is running in thread " + Thread.currentThread().getName());
}
public static void main(String[] args) {
ThreadForT1 t = new ThreadForT1();
t.run();
}
}
class ThreadForT1 implements Runnable {
public void run() {
System.out.println("Thread for T1 is running in thread " + Thread.currentThread().getName());
}
public static void main(String[] args) {
ThreadForT1 t = new ThreadForT1();
t.run();
}
}
@sne007
sne007 / Threads.java
Last active September 23, 2020 06:12
class ThreadForT1 extends Thread{
public void run() {
System.out.println("Thread for T1 is running in thread " + Thread.currentThread().getName());
}
public static void main(String[] args) {
ThreadForT1 t = new ThreadForT1();
t.run();
}
}
@sne007
sne007 / ExecService.java
Created September 20, 2020 19:37
ExecutorService
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
public class Main {
public static void main(String[] args) {
ExecutorService s = Executors.newFixedThreadPool(2);