We have a service method GetDataParallel( ) which maybe called by many clients currently, and we use the ExecutorService to called the MyCallable inside it. However I found unless I called the executorService.shutdown(); the application never exit, so why the application cannot exit , we must shut down all thread pool threads manually before the application exit? and in service environment I think we don't need to call the executorService.shutdown(); to keep the application alive, right ?
import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class MultiThreading { static ExecutorService executorService = Executors.newFixedThreadPool(100); private List<String> _BusinessUnits= new ArrayList<String>(); public static void main(String[] args) throws Exception { MultiThreading kl =new MultiThreading(); kl.GetDataParallel(); Thread.sleep(10000); System.out.println("111111111"); //executorService.shutdown(); } public void GetDataParallel( ) throws Exception { _BusinessUnits.add("BU1"); _BusinessUnits.add("BU2"); _BusinessUnits.add("BU3"); for(final String v : _BusinessUnits) { ExecutorServiceTest.executorService.submit( new MyCallable()); } } } class MyCallable implements Callable { @Override public String call() throws Exception { Thread.sleep(1000); //return the thread name executing this callable task System.out.println(Thread.currentThread().getName()); return Thread.currentThread().getName(); } }