Java tutorial
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class Main implements Runnable { public static void main(String[] args) throws InterruptedException { Main task = new Main(); int threads = Runtime.getRuntime().availableProcessors(); ExecutorService pool = Executors.newFixedThreadPool(threads); for (int i = 0; i < threads; i++) { pool.submit(task); } pool.awaitTermination(120, TimeUnit.SECONDS); } public void run() { System.out.println("Task running..."); int i = 0; while (true) { i++; } } }