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
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(); | |
} | |
} |
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
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(); |
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
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(); | |
} | |
} |
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
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(); | |
} | |
} |
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
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(); | |
} | |
} |
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
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(); | |
} | |
} |
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
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); |