/ Published in: Java
This is a simple Java multithreading example that uses ActualThread as the class in which the thread code is contained. ActualThread must implement runnable.
Expand |
Embed | Plain Text
ExecutorService executor = Executors.newFixedThreadPool(threadAmount); List<Callable<Object>> tasks = new ArrayList<Callable<Object>>(); for (int i = 1; i < 50; i++) { tasks.add(Executors.callable(new ActualThread(i))); } executor.invokeAll(tasks); executor.shutdown(); // not really necessary if the executor goes out of scope.
You need to login to post a comment.
