Here's a code snippet that creates an executor and submits two tasks to it:
ExecutorService executor = Executors.newFixedThreadPool(4);
for (int i = 1; i <= 2; i++) {
int taskNumber = i;
executor.submit(() -> System.out.println("Starting task-" + taskNumber));
}
TimeUnit.MILLISECONDS.sleep(50); // the current thread waits for 50 millis
executor.shutdown();
System.out.println("Main completed");
Here is an output of one execution of the program:
Main completed
Starting task-1
Starting task-2
Select one correct statement about orders of lines in the output.