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.
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.
subject: How can i lock thirdparty class methods which are not synchronized.