@@ -0,0 +1,1468 @@
+package com.atreceno.it.javanese.concurrency;%0A%0Aimport java.util.concurrent.BlockingQueue;%0Aimport java.util.concurrent.LinkedBlockingQueue;%0Aimport java.util.concurrent.ThreadPoolExecutor;%0Aimport java.util.concurrent.TimeUnit;%0A%0Apublic class SplitWorkIntoThreads %7B%0A%0A%09public static void main(String%5B%5D args) throws InterruptedException %7B%0A%09%09System.out.println(%22Start%22);%0A%09%09SplitWorkIntoThreads split = new SplitWorkIntoThreads();%0A%09%09split.start();%0A%09%7D%0A%0A%09private void start() throws InterruptedException %7B%0A%09%09BlockingQueue%3CRunnable%3E queue = new LinkedBlockingQueue%3CRunnable%3E();%0A%09%09/* There are 10 tasks to work on */%0A%09%09for (int i = 0; i %3C 3; i++) %7B%0A%09%09%09final int j = i;%0A%09%09%09queue.add(new Runnable() %7B%0A%0A%09%09%09%09@Override%0A%09%09%09%09public void run() %7B%0A%09%09%09%09%09doSomething(j);%0A%09%09%09%09%7D%0A%09%09%09%7D);%0A%09%09%7D%0A%09%09ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 3, 1000,%0A%09%09%09%09TimeUnit.MILLISECONDS, queue);%0A%09%09executor.prestartAllCoreThreads();%0A%09%09executor.shutdown();%0A%09%09executor.awaitTermination(100000, TimeUnit.MILLISECONDS);%0A%0A%09%09System.out.println(%22End%22);%0A%09%7D%0A%0A%09private double doSomething(int i) %7B%0A%09%09System.out.println(%22Thread %22 + Thread.currentThread().getName()%0A%09%09%09%09+ %22 is working on task #%22 + i);%0A%09%09double result = 1;%0A%09%09for (int j = 0; j %3C 100; j++) %7B%0A%09%09%09result *= Math.sqrt(i + j);%0A%09%09%7D%0A%09%09try %7B%0A%09%09%09Thread.sleep(i * 1000);%0A%09%09%7D catch (InterruptedException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09System.out.println(%22Thread %22 + Thread.currentThread().getName()%0A%09%09%09%09+ %22 finished task #%22 + i);%0A%09%09return result;%0A%09%7D%0A%7D%0A

Add class to split work