Come to Java multi-thread design mode
Assign a thread to each command or request for execution.
Public Class Host {
Private Final Helper helper = New Helper ();
Public Void Request ( Final Int Count, Final Char C ){
System. Out. println (" Request ( "+ Count +" , "+ C +" ) Begin ");
New Thread (){
Public VoidRun (){
Helper. Handle (count, C );
}
}. Start ();
System. Out. println (" Request ( "+ Count +" , "+ C +" ) End ");
}
}
Public ClassMain {Public Static VoidMain (string [] ARGs) {system. Out. println ("Main begin"); Host =NewHost (); host. request (10, 'A'); host. request (20, 'B'); host. request (30, 'C'); system. out. println ("Main end");}}
Request creates a new thread that calls the handle method of helper to solve the time consumption of handle and improve the responsiveness of the client.
However, it takes time to start the thread in the host (Worker pattern ).