Ideally, I would suggest wrapping third-party software in a separate application that runs on only one instance. This way you can handle the lock using EJB @Singleton (I believe @Singleton will not help you in your scenario) and expose it using remote EJB / WS. It seems like this piece of software is a little nasty (single-threaded?), So a more convenient EJB interface will be an added advantage.
Think about it - if you can access the library once at a time for the entire system, why distribute it? In any case, any instance can always be used.
If you want to stick to a uniform distributed system (which is not a bad idea at all), I would suggest locking the database using SELECT FOR UPDATE . I have never tried, but I think that issuing such SQL code before using your library (getting a lock) and letting the EJB container complete the transaction (actually releasing the lock) will subsequently do the trick.
source share