Application setup

Report a typo

Create an ExecutorService with a single thread. Submit tasks one by one in the given order. Don't forget to stop the service.

Write a program in Java 17
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

class Main {
public static void main(String[] args) {
List<Runnable> tasks = readTasks();

// create an instance with a single thread, submit tasks and shutdown the instance
}

// do not change the method
private static List<Runnable> readTasks() {
Scanner scanner = new Scanner(System.in);
int count = scanner.nextInt();
scanner.nextLine(); // read rest of the first line
return IntStream
.rangeClosed(1, count)
.mapToObj(i -> (Runnable) () -> System.out.println("Task #" + i + " completed: " + scanner.nextLine()))
.toList();
}
}
___

Create a free account to access the full topic