Home CompletableFuture implementation with dynamic multiple threads not working
Reply: 0

CompletableFuture implementation with dynamic multiple threads not working

user4870 Published in September 19, 2018, 9:10 am

Regarding CompletableFuture functionality, if anyone has idea about it is not creating multiple threads dynamically. For that i have tried with executorService also in below code but executorService has a fixed thread pool so it goes to blocking state. Can you please help to implement CompletableFuture in multithreading dynamically as per below code?

private static CompletableFuture<Integer> createCompletableFuture(ByteArrayOutputStream baOS, int totalBytes, 
            List<FileUploadMultiLocator> fileUploadList) {
        CompletableFuture<Integer> futureCount = CompletableFuture.supplyAsync(
                () -> {
                    try {
                            // simulate long running task
                            for (FileUploadMultiLocator fileUploadMultiLocator : fileUploadList) {
                                System.out.println(Thread.currentThread().getName() + " secondary task is called");
                                fileUploadMultiLocator.baOS.write(baOS.toByteArray(), 0, totalBytes);
                                new Thread(fileUploadMultiLocator).start();
                                try {
                                } catch (InterruptedException e) {
                                    // TODO Auto-generated catch block
                    catch (Exception e) { }
                    return 20;
        return futureCount;
share|improve this question

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.461128 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO