Thread pool-2
Subclass implementation interface:
import java. util. concurrent. Callable; /* * The implementation class of callable interface appears as a thread submitting task * use the method return value * * / public class threadpoolcallable implements callable < string > {public string call() {return "ABC";}
}
Test class:
import java. util. concurrent. ExecutorService; import java. util. concurrent. Executors; import java. util. concurrent. Future; /* * The third way to implement the thread program is to implement the callable interface * implementation steps * factory class executors static method newfixedthreadpool method, create the thread pool object * thread pool object executorservice interface implementation class, Call the method submit to submit the thread task * SUBMIT (callable C) * / public class threadpooldemo1 {public static void main (string [] args) throws exception {executorservice ES = executors. Newfixedthreadpool (2); / / the method submit to submit the thread task returns the implementation class of the future interface future < string > F = es. Submit (New threadpoolcallable()); string s = f.get() ; System. out. println(s); } }