permaculture playing cards*
The moose likes Servlets and the fly likes Question involving servlet output and synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Question involving servlet output and synchronization" Watch "Question involving servlet output and synchronization" New topic
Author

Question involving servlet output and synchronization

Tod Checker
Greenhorn

Joined: Feb 19, 2004
Posts: 27
Is it a bad idea to synchronize the output of a servlet, by creating a singleton class which handles the html?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60783
    
  65

Yes. Unnecessary synchronization will result in poor performance. Is this related to your other synchronization question?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tod Checker
Greenhorn

Joined: Feb 19, 2004
Posts: 27
Yes they are all related
Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
So, how would one synchronize parts of a , servlet?
using the synchronized key word?
john smith
Ranch Hand

Joined: Mar 04, 2004
Posts: 75
Don't use synchronized at all in servlets. Thread management is up to the container. You can get some way to the same behaviour that synchronized would give you by having your servlet implement the (now deprecated) interface javax.servlet.SingleThreadModel. I'd be curious to know why you need this functionality?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
If your servlet has an instance variable that must only be accessed by one request Thread at a time, of course you use synchronized code. When designing a servlet one normally strives to reduce or eliminate the necessity for synchronized access, but sometimes it is necessary.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question involving servlet output and synchronization
 
Similar Threads
include() methos of RequestDispatcher?
Disabling servlet caching
Servlet - Urgent help required.
Sent data to different Application servlet
Servlets vs JSP