This week's giveaway is in the Java/Jakarta EE forum. We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line! See That is, until you identify an actual performance problem and have used profiling tools to identify the real bottleneck.
1. Create static data in init() method so it will be created only once and create dyanamic data in service() method. 2. Use StringBuffer instead of using + operator with string when you concatenate multiple strings 3. Dont user println() method, use print() method as println() internally calls print() method. 4. Always initialize the PrintWriter with proper size 5. flush the data 6. dont put unnecssary code in sysnchronized blocks if you are using in service() method. 7. always clean up the resoruces like JDBC connections, sockets in destroy() method 8. dont put unnecssary data in session. 9. choose the rite session mechanism. 10. remove session explicitly when you dont require the session. 11. disable servlet reloading if the servlet is not required to load always. 12. Use 'transient' variables to reduce serialization overhead if your HttpSession tracking mechanism uses serialization process. 13. use session time out value to reduce the session time
I have to say that about half of that list is useless and misdirected in terms of real world servlets. Furthermore you left out - choose the right architecture / algorithms. First make your code clear and bug-free, Then if you have a performance problem - follow the advice of the other old-timers as given above. For your own amusement, do a google search for "premature optimization is the root of all evil" Bill