package dk.thoerup.traininfoservice; import java.io.IOException; import java.sql.SQLException; import java.util.Random; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class TestServlet extends HttpServlet { private static final long serialVersionUID = 1L; Random r = new Random(); //South-West corner= 54.0, 7.0 //North-East corner= 58.0, 13.0 //Latitude span=4.0 //Longitude span=6.0 void testFindNearest(int count) throws SQLException { StationDAO db = new StationDAO(); for (int i=0; i0) sb.append(','); sb.append(r.nextInt(400)); } sb.append(')'); db.getByList(sb.toString()); } } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String test = request.getParameter("test"); String strCount = request.getParameter("count"); int count = Integer.parseInt(strCount); try { long start = System.currentTimeMillis(); if ( test.equals("name") ) { testFindName(count); } else if ( test.equals("nearest") ) { testFindNearest(count); } else if ( test.equals("favorites") ) { testFindFavorites(count); } else { throw new ServletException("No parameter test"); } long stop = System.currentTimeMillis(); long elapsed = stop-start; float avg = ((float)elapsed) / count; String out = "Count=" + count + "\n" + "Elapsed=" + elapsed + "\n" + "Avg.=" + avg; response.getWriter().print( out ); } catch (Exception e) { throw new ServletException(e); } } }