Allow making Worker Threads and Using them in a Thread Pool!
A ThreadPool has 2 Type Parameters. The first is the Input, the second is the Output.
If the ThreadPool isn't given a number it takes the amount of Threads given by the Processor.
ThreadPool<Integer, Boolean> pool = new ThreadPool(2);
//Creates a ThreadPool with 2 Threads which takes an Integer and outputs a BooleanThe input can be any List of the First Type Parameter given to the ThreadPool.
pool.setInput(Arrays.asList(1, 2 , 3, 4));The Operation is an Interface of the type ThreadTask.
pool.setCalculations(input -> {
//Put Operation here!
});A Direct Data Processor is triggered everytime a new result is Finished.
pool.addDirectDataProcessor((input, result) -> {
//Process Data here!
});An All Data Processor is triggered after all Operations are completed.
pool.setAllDataProcessor(input -> {
//Process all Data here
});This is optional but if the Delay between checking if the Threads are Finished is too Long or too short for your use case.
The Default delay is 1000 Milliseconds.
pool.setHypervisorDelay(100);After all of that the ThreadPool must be started.
pool.start();