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.
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...
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: How can i lock thirdparty class methods which are not synchronized.