• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic