Code example for ThreadPoolExecutor

Methods: awaitTermination, shutdown, shutdownNow

0
			pool.submit(dlTask);
	} 
 
	@Override 
	protected void finalize() throws Throwable { 
		pool.shutdown(); // shutdown idle threads/tasks
		pool.shutdownNow(); // Cancel currently executing tasks
	    // Wait a while for tasks to respond to being cancelled 
	    if (!pool.awaitTermination(10, TimeUnit.SECONDS))
	       System.err.println("Some downloaders did not terminate");
	        
		super.finalize(); 
	} 
	 
	public long getSize() { 
		return pool.getTaskCount();
	} 
	 
}