Guest User

Untitled

a guest
May 27th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. package net.jcip.examples;
  2.  
  3. import java.io.IOException;
  4. import java.net.ServerSocket;
  5. import java.net.Socket;
  6.  
  7. /**
  8. * ThreadPerTaskWebServer
  9. * <p/>
  10. * Web server that starts a new thread for each request
  11. *
  12. * @author Brian Goetz and Tim Peierls
  13. */
  14. public class ThreadPerTaskWebServer {
  15. public static void main(String[] args) throws IOException {
  16. ServerSocket socket = new ServerSocket(80);
  17. while (true) {
  18. final Socket connection = socket.accept();
  19. Runnable task = new Runnable() {
  20. public void run() {
  21. handleRequest(connection);
  22. }
  23. };
  24. new Thread(task).start();
  25. }
  26. }
  27.  
  28. private static void handleRequest(Socket connection) {
  29. // request-handling logic here
  30. }
  31. }
Add Comment
Please, Sign In to add comment