We are usually exposed to multithreaded thread,runnable, both of which cannot return the results of a thread after execution.
Callable and the future, the former produces results, the latter gets results.
Callable and the future recommend a good blog: http://blog.csdn.net/ghsau/article/details/7451464
Public classGreystartservletextendsHttpServlet {@Override Public voidInit ()throwsservletexception {Futuretask<String> task =NewFuturetask<string> (NewCallable<string>() {@Override PublicString Call ()throwsException {start ();//using another thread to execute the method avoids the use of Tomcat's boot time return"Collection completed"; } }); NewThread (Task). Start (); } //methods that you want the tomcat to execute after the boot ends Private Static voidStart ()throwsException {thread.sleep (1000);
}}
Java multithreaded Callable,future,futuretask