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

CompletableFuture implementation with dynamic multiple threads not working

user1755
1#
user1755 Published in July 21, 2018, 4:09 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);
                                fileUploadMultiLocator.setTotalBytes(totalBytes);
                                new Thread(fileUploadMultiLocator).start();
                                try {
                                    Thread.sleep(5);
                                } catch (InterruptedException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }
                        }
                    catch (Exception e) { }
                    return 20;
                });
        return futureCount;
    }
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO