0% found this document useful (0 votes)
2 views1 page

Code2pdf 67631fd8cea11

The document is a Java program that demonstrates the use of futures with an ExecutorService to fetch names concurrently. It creates four tasks to fetch names and submits them to a fixed thread pool. The program retrieves and prints the results of each task before shutting down the service.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Code2pdf 67631fd8cea11

The document is a Java program that demonstrates the use of futures with an ExecutorService to fetch names concurrently. It creates four tasks to fetch names and submits them to a fixed thread pool. The program retrieves and prints the results of each task before shutting down the service.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

package in.kgcoding.executor.

future;

import java.util.concurrent.*;

public class TestingFutures {


public static void main(String[] args) throws ExecutionException, InterruptedException {
ExecutorService service = Executors.newFixedThreadPool(1);
FetchName task1 = new FetchName("Prashant");
FetchName task2 = new FetchName("Sanchit");
FetchName task3 = new FetchName("KG Coding");
FetchName task4 = new FetchName("Subscribe");

Future<String> name1 = service.submit(task1);


Future<String> name2 = service.submit(task2);
Future<String> name3 = service.submit(task3);
Future<String> name4 = service.submit(task4);

System.out.printf("\nFull Name is: %s", name1.get());


System.out.printf("\nFull Name is: %s", name2.get());
System.out.printf("\nFull Name is: %s", name3.get());
System.out.printf("\nFull Name is: %s", name4.get());

service.shutdown();
}
}

You might also like