• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

How can we optimise the servlets

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
friends i have a basic question in servlets i.e
how can we optimize our servlets?
(i.e how can we improve the performance of the servlet)
kindly help me
vinay
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
either u have to implement SingleThreadModel interface or u have to make a method Synchronise which is to be invoked by multiple users.
this is upto ur application , wheter it is single user or multiuser where multiple users r supposed to acces it .
 
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
kishor, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

thanks,
bear
Forum Bartender
 
Bear Bibeault
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

u have to implement SingleThreadModel interface



Bad advice all around. Not only is that interface deprecated, it will do nothing to improve performance -- in fact, it will probably adversely affect it.

The best advice when it comes to optimization is: don't.

That is, until you identify an actual performance problem and have used profiling tools to identify the real bottleneck.
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:

The best advice when it comes to optimization is: don't.

That is, until you identify an actual performance problem and have used profiling tools to identify the real bottleneck.



I second that.
Invest in a good profiler and test.
The bottlenecks are often not where you would expect them to be.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic