This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Synchronize or go for object pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Synchronize or go for object pooling" Watch "Synchronize or go for object pooling" New topic
Author

Synchronize or go for object pooling

Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687

hi all
i am using a user defined exception in my project to indicate whether the operation done by a particular method is a success or a failure.
A large no of components are goin to use this exception for signalling of the failure thru a log writer which will throw the exception
the flow is somewhat like this
Component.method(fails)>>LOGWriter.StaticMethod()>>MyException.
* the LOGWriter is a class having a static method
which writes the errormesg to a file as well as throw the error.
now the question b4 me is when the traffic gets heavy i think the LOGWriter may not be able to handle the flow even with synchronisation.
pls suggest any solution for the scenario keeping heavy traffic as the primary requirement.......
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
You are likely to get scalability problems, but not where you think - it might well be the exception handling that's going to bite you. Please realise that throwing an exception is a heavyweight operation. Exceptions should be just that: ways to handle exceptional cases that are not part of the normal program flow. If you expect a sizeable number of operations to fail then arguably that should not be handled using an exception.
- Peter
Zakaria Haque
Ranch Hand

Joined: Jan 02, 2002
Posts: 60
I am not sure why you are throwing the exception from the LOGWriter's method, not the component's method. However, for high traffic it would be best to keep the method threadsafe without using synchronization, that is by using local variables only.


tobe bondhu nouka bherao<br />shonabo gaan aj shara raat
 
jQuery in Action, 2nd edition
 
subject: Synchronize or go for object pooling