painfully slow servlet


Web tier: servlets, JSP, Web frameworks: painfully slow servlet

  1. painfully slow servlet (1 messages)

    hi there,

    i've developed small servlets in the past and had no problems with regard to speed, my newest project is involving a considerably larger servlet than what i am used to and the time taken for the servlet to generate a results page (embedded in the servlet)is v.slow.
    is there a way of optimizing large servlets?


  2. painfully slow servlet[ Go to top ]

    Refactor it:

    1) Split the logic in your servlet up into smaller units. Start by splitting them up into methods, then move those methods to other classes. Remove as much duplicate code as you can in this process.

    2) Isolate the logic that must run in the web environment (because it talks to the request/response/session) from logic that can run in a standalone Java application (string/file/database manipulation).

    3) Test components separately, starting with the code that is web-independent. Find the slowest stuff and fix it.

    Remember, a servlet is just a Java class, and you can use all your usual OO tricks for encapsulation, reuse and optimization.