I'm developing an application in which there are many short-lived tasks which are run in separate threads. I've developed a generic and reusable system to handle such a requirement. The code snippet given below is using this system code plus the example client code to show how to use the system's API.package com.demo;import java.util.concurrent.Callable;import java.util.concurrent.ExecutionException;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.concurrent.Future;import java.util.concurrent.TimeUnit;////////////////////////API to handle short lived async task////////////////////////////////////////////* * This class holds the threadpool executor instance and provide the submit method which in turn submit the task * to executor */class AsyncTaskManager{    private ExecutorService service;public AsyncTaskManager(ExecutorService service){    this.service = service;}public <T> Future<T>  submit(Callable<T> callable){    Future<T> result = service.submit(callable);    return result;}public void shutdown(){    service.shutdown();    try {        service.awaitTermination(60, TimeUnit.SECONDS);    } catch (InterruptedException e) {        service.shutdownNow();    }    service.shutdownNow();}}/** * This is a wrapper class on Task object to make it async * @author jayesh * * @param <T> * @param <V> */class AsyncTask<T extends Task<V>, V> implements Callable<V>{private Task<V> task;public AsyncTask(Task<V> task){    this.task = task;}@Overridepublic V call() throws Exception {    return task.doTask();}}/** * Client will implement this interface to perform the task * @author jayesh * * @param <V> */interface Task<V>{    public  V doTask();}/////////////////////////////////////////End of API //////////////////////////////////////////////////////////////Use of API by client code /////////////////////////////////////////////public class AsyncTaskManagerDemo {public static void main(String[] args) throws InterruptedException, ExecutionException {    AsyncTaskManager taskManager = new AsyncTaskManager(Executors.newCachedThreadPool());    Task<String> urlLoader = new UrlLoaderTask(http://www.google.com);    Task<Integer> wordCounter = new WordCounterTask(/var/tmp/test.txt);    AsyncTask<Task<String>, String> asyncUrlLoader = new AsyncTask<Task<String>, String>(urlLoader);    AsyncTask<Task<Integer>, Integer> asyncWordCounter = new AsyncTask<Task<Integer>, Integer>(wordCounter);    Future<String> urlLoaderResult = taskManager.submit(asyncUrlLoader);    System.out.println(urlLoaderResult.get());    Future<Integer> wordCounterResult = taskManager.submit(asyncWordCounter);    System.out.println(wordCounterResult.get());    taskManager.shutdown();}}/** * Task implementation which do the  task and returns result * @author xxx * */class UrlLoaderTask implements Task<String>{private String url;public UrlLoaderTask(String url){    this.url = url;}@Overridepublic String doTask(){    try {        Thread.sleep(3000);    } catch (InterruptedException e) {        // TODO Auto-generated catch block        e.printStackTrace();    }    return returning content of url -  + url;}};/** * Task implementation which do the  task and returns result * @author xxx * */class WordCounterTask implements Task<Integer>{private String filePath;public WordCounterTask(String filePath){    this.filePath = filePath;}@Overridepublic Integer doTask(){    try {        Thread.sleep(5000);    } catch (InterruptedException e) {        // TODO Auto-generated catch block        e.printStackTrace();    }    return 1000; //returning no of words in a file}};I am looking for a review on my system and its API.
System to handle the short lived async task
java;multithreading;api;generics;library