Skip to content

Instantly share code, notes, and snippets.

@damithadayananda
Created December 29, 2018 08:23
Show Gist options
  • Save damithadayananda/70d233f6b783f1df0d19b2a3078d8399 to your computer and use it in GitHub Desktop.
Save damithadayananda/70d233f6b783f1df0d19b2a3078d8399 to your computer and use it in GitHub Desktop.
package taskExecutor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
public class FixedThreadPoolExecutor {
public FixedThreadPoolExecutor(){
ThreadPoolExecutor executor = (ThreadPoolExecutor)Executors.newFixedThreadPool(4);
for(int i=0; i<10;i++){
Task task = new Task("Task" + i);
System.out.println("A new task has been added: "+ task.getName());
executor.execute(task);
}
System.out.println("Maximum threads inside pool " + executor.getMaximumPoolSize());
executor.shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment