rava2
home
documentation
examples
// retoor <retoor@molodetz.nl> public class Main { public static void main(String[] args) { System.out.println("=== Thread Worker Pool Example ===\n"); System.out.println("Starting 3 workers with different tasks\n"); Thread w1 = new Thread(() -> { processTask("Worker-1", "Calculate Pi", 100); }); Thread w2 = new Thread(() -> { processTask("Worker-2", "Process Data", 200); }); Thread w3 = new Thread(() -> { processTask("Worker-3", "Generate Report", 150); }); long startTime = System.currentTimeMillis(); w1.start(); w2.start(); w3.start(); w1.join(); w2.join(); w3.join(); long endTime = System.currentTimeMillis(); System.out.println("\nAll workers completed in " + (endTime - startTime) + "ms"); } static void processTask(String worker, String task, int workTime) { System.out.println("[" + worker + "] Starting: " + task); Thread.sleep(workTime); System.out.println("[" + worker + "] Completed: " + task + " (" + workTime + "ms)"); } }
run program
ready