aspose file tools*
The moose likes Threads and Synchronization and the fly likes How can i lock thirdparty class methods which are not synchronized. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "How can i lock thirdparty class methods which are not synchronized." Watch "How can i lock thirdparty class methods which are not synchronized." New topic
Author

How can i lock thirdparty class methods which are not synchronized.

Bhagya Tangutur
Ranch Hand

Joined: Oct 21, 2002
Posts: 88
Is any one aware of Synchoronizing all methods in class.
I have a third party class.whose methods are not synchronized.
but when i am using that class in my application.I used extensively.now we have a case where there is a chance of dead lock.because the same class is accessed from two different threads.
one solution to this is subclass the third party class and ovveride all methods to become synchronized.and replace thirparty class/Objectc with it's subclass.
but i don't want to change the code all over.so is there any way i can just lock the object/Class in one place.so that it acts as if it acquired lock on the Object/Class.

your sussestions are greatly appreciated....or alternative/better approaches are most welcome.

Thanks


Sun Certified Java Programmer
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
If you have control over all the client code, the easiest solution is probably just to wrap all access with a custom object that handles synchronization. If you don't, you might want to consider Aspect-Oriented Programming solutions that rewrite the bytecode of the offending classes at load-time...
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
Can't you handle the object locking in your code? Synchronize all instance access in a synchronize block. If you don't want to do this (because you'd have to change your code) there's a really nasty solution.
*** DISCLAIMER - NOT RECOMMENDED ***
Use the JAD decompiler to decompile the class you'd like synchronized, put in the synchronize modifiers, and recompile it (packaging it in the same JAR as the rest of the third party stuff if needed) overwriting the old version.
Now pray to god that your company never uses a different version of that library.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can i lock thirdparty class methods which are not synchronized.