Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Bhagya Tangutur
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic