Search code examples
javaosgiequinoxsynchronize

Osgi synchronization services


It is posible to syncronize an osgi service from outside it,from an other bundle ?

OsgiService oS = retrieveService(BundleContext);

synchronized(oS){
...
}

I dont want to alow the calls from outside a bundle to do changes during a specific method execution inside.

The bundle is registered and active. I am working under Equinox framework.


Solution

  • No. When you publish a service you declare it as being generally available, without constraints on the way in which it is used. For example you cannot limit other bundles to call methods in a particular order, or require them to use synchronization, or to always call from a particular thread. Therefore you must assume that you will be called from any thread, without synchronization, etc.

    If the internal state of your service implementation is fragile and requires synchronization, then it is your responsibility to do it inside your implementation. You cannot force this work onto somebody else.