File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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
* 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
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
I agree. Here's the link:
subject: Synchronize or go for object pooling
It's not a secret anymore!