Using Executor Service with Java 8 — Part II (Using List Partition)

List<List<File>> partitionedLists = partitionListOfFiles(fileList, 3);for(List<File> files : partitionedLists) {
Runnable worker = new ProcessFilesUsingListPartition(files);
executorService.submit(worker);
}
private static List<List<File>> partitionListOfFiles(List<File> files, final int breakInto) {    List<List<File>> fileParts = new ArrayList<>();
final int totalFiles = files.size();
for (int i = 0; i < files.size(); i += breakInto) {
fileParts.add(
new ArrayList<>(
files.subList(i,Math.min(totalFiles, i + breakInto))
)
);
}
return fileParts;
}

--

--

--

Senior Software Developer | Java Enthusiast | Coding | Blogging | Cycling | @ https://www.dynamicallyblunttech.com/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Bulk RDBMS Upserts with Spring

Introduction to Elm Programming- the Future of Front-End Development

#KCN: Oracle prophecy

What is NGINX & Why you should use it now?

Getting started with …. any new programming language

Programming Languages — There is a sea of them

How to build a killer GitHub portfolio (in 30 minutes)

Le Wagon Demo Day, batch #299: — The Le Wagon Coding Bootcamp helps you with a career change

Ehcache Implementation for Database Operations in Spring Boot

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ankit agrahari

ankit agrahari

Senior Software Developer | Java Enthusiast | Coding | Blogging | Cycling | @ https://www.dynamicallyblunttech.com/

More from Medium

Immutable String in Java

Java Reflection, part 2: fields, methods, constructors

How Java Virtual Machine Works?

Merge or Split Tables and Cells in Word Documents using Java