Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.53 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package controller;
  2.  2
  3.  3 import java.util.Map;
  4.  4 import javax.servlet.http.HttpServletRequest;
  5.  5 import javax.servlet.http.HttpServletResponse;
  6.  6 import org.springframework.web.servlet.ModelAndView;
  7.  7 import org.springframework.web.servlet.View;
  8.  8 import org.springframework.web.servlet.mvc.AbstractController;
  9.  9
  10. 10 /**
  11. 11  *
  12. 12  * @author josh
  13. 13  */
  14. 14 public class SlowController extends AbstractController {
  15. 15
  16. 16     public SlowController() {
  17. 17     }
  18. 18    
  19. 19     protected ModelAndView handleRequestInternal(
  20. 20             HttpServletRequest request,
  21. 21             HttpServletResponse response) throws Exception {
  22. 22
  23. 23         long start = System.currentTimeMillis();
  24. 24         Thread.sleep(100); //not picked up by profiler
  25. 25         double[] b = new double[100000];
  26. 26         for (int i = 0; i < b.length; i++){
  27. 27             b[i] = (Math.pow(i, 4) + Math.pow(i, 3) + Math.pow(i, 2));
  28. 28         } //picked up by profiler - around 80ms on my MacBook
  29. 29         long stop = System.currentTimeMillis();
  30. 30
  31. 31         long executionDelay = stop - start;
  32. 32         request.setAttribute("execDelay", executionDelay);
  33. 33
  34. 34         return new ModelAndView(new View(){
  35. 35             public String getContentType() {return "text/html";}
  36. 36             public void render(Map map, HttpServletRequest request, HttpServletResponse response) throws Exception {
  37. 37                 response.getWriter().println("<h1>Slow Controller returned! " + request.getAttribute("execDelay") + "</h1>");
  38. 38             }
  39. 39         });
  40. 40     }
  41. 41
  42. 42 }
  43. 43