aspose file tools
The moose likes Servlets and the fly likes Question involving servlet output and synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply 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: 56214
    
  13

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 12271
    
    1
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Question involving servlet output and synchronization
 
Similar Threads
include() methos of RequestDispatcher?
Servlets vs JSP
Sent data to different Application servlet
Disabling servlet caching
Servlet - Urgent help required.