Web multi-thread job

Source: Internet
Author: User
1   Import  Java. Io. printwriter;  2   Import  Java.net. serversocket;  3   Import  Java.net. Socket;  4   5   Public   Class  Test {  6       Public   Static  Void Main (string [] ARGs) Throws  Exception {  7 Serversocket Server = New Serversocket (8888 );  8           While ( True  ){  9 Socket S = Server. Accept ();  10 Processer P = New Processer (s );  11 Thread t = New  Thread (P );  12   T. Start ();  13   }  14   }  15   }  16   17   Class Processer Implements Runnable {  18       Private  Socket socket;  19   20       Public Processer (socket s ){ //  Todo auto-generated constructor stub  21           This . Socket = S;  22   }  23   24  @ Override  25       Public   Void  Run (){  26           Try  {  27 Printwriter out = New Printwriter (socket. getoutputstream (), True  );  28 Out. println ("HTTP/1.0 200 OK" );  29 Out. println ("Content-Type: text/html; charset = UTF-8" );  30   Out. println ();  31 Out. println (" );  32   Out. Close ();  33 } Catch  (Exception ex ){  34   Ex. printstacktrace ();  35 }Finally  {  36               Try  {  37   Socket. Close ();  38 } Catch  (Exception e ){  39   E. printstacktrace ();  40   }  41   } 42   }  43 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.