I need to run plugins in parallel, I'm trying with multithreading but I have no idea on how to close the thread when the task is gone, or do I even need to close it ? Since it's a program just run, display something and end almost immediatly, so if there are some unused threads in the background it don't change much i guess ?
Here is how it look right now, does it look good ?
ArrayList<Thread> listOfThreads = new ArrayList<>();
pluginsList.forEach( ( plugin ) -> {
Thread thread = new Thread( () -> plugin.run() );
thread.start();
listOfThreads.add( thread );
} );
// closing all threads
listOfThreads.forEach( ( thread ) -> thread.stop() );