Created
July 2, 2011 01:23
-
-
Save javajosh/1059651 to your computer and use it in GitHub Desktop.
Just a SpringMVC controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controller; | |
2 | |
3 import java.util.Map; | |
4 import javax.servlet.http.HttpServletRequest; | |
5 import javax.servlet.http.HttpServletResponse; | |
6 import org.springframework.web.servlet.ModelAndView; | |
7 import org.springframework.web.servlet.View; | |
8 import org.springframework.web.servlet.mvc.AbstractController; | |
9 | |
10 /** | |
11 * | |
12 * @author josh | |
13 */ | |
14 public class SlowController extends AbstractController { | |
15 | |
16 public SlowController() { | |
17 } | |
18 | |
19 protected ModelAndView handleRequestInternal( | |
20 HttpServletRequest request, | |
21 HttpServletResponse response) throws Exception { | |
22 | |
23 long start = System.currentTimeMillis(); | |
24 Thread.sleep(100); //not picked up by profiler | |
25 double[] b = new double[100000]; | |
26 for (int i = 0; i < b.length; i++){ | |
27 b[i] = (Math.pow(i, 4) + Math.pow(i, 3) + Math.pow(i, 2)); | |
28 } //picked up by profiler - around 80ms on my MacBook | |
29 long stop = System.currentTimeMillis(); | |
30 | |
31 long executionDelay = stop - start; | |
32 request.setAttribute("execDelay", executionDelay); | |
33 | |
34 return new ModelAndView(new View(){ | |
35 public String getContentType() {return "text/html";} | |
36 public void render(Map map, HttpServletRequest request, HttpServletResponse response) throws Exception { | |
37 response.getWriter().println("<h1>Slow Controller returned! " + request.getAttribute("execDelay") + "</h1>"); | |
38 } | |
39 }); | |
40 } | |
41 | |
42 } | |
43 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment