xref: /unit/test/java/threads/app.java (revision 1685:87018c5bab9f)
1 
2 import java.io.IOException;
3 
4 import javax.servlet.ServletException;
5 import javax.servlet.annotation.WebServlet;
6 import javax.servlet.http.HttpServlet;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9 
10 @WebServlet("/")
11 public class app extends HttpServlet
12 {
13     @Override
doGet(HttpServletRequest request, HttpServletResponse response)14     public void doGet(HttpServletRequest request, HttpServletResponse response)
15         throws IOException, ServletException
16     {
17         int delay = 0;
18 
19         String x_delay = request.getHeader("X-Delay");
20         if (x_delay != null) {
21             delay = Integer.parseInt(x_delay);
22         }
23 
24         try {
25             Thread.sleep(delay * 1000);
26         } catch (InterruptedException ex) {
27             ex.printStackTrace();
28         }
29 
30         response.addHeader("X-Thread", "" + Thread.currentThread().getId());
31     }
32 }
33