Multithreading in Java using ThreadPoolExecutor

ThreadWorker is your custom class.

1
2
3
4
5
6
7
8
9
try {
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(MAX_THREAD_SIZE);
for (int i = 1; i Random randomGenerator = new Random();
executor.submit(new ThreadWorker("worker" + i, randomGenerator.nextInt(10)));
LOG.info(i);
}
} catch (Exception e) {
LOG.error("Hmm something is not right.", e);
}
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


− two = 0