tags:

views:

78

answers:

1

I'm starting to delve into using Spring DM and OSGi services in an RCP application. I've created a service which is used by another bundle in the RCP application. It does a lookup of the service via calls to getBundleContext().getServiceReference() using the explicit bundle names and service class names. I'm not using DI anywhere yet. The issue I'm running into is that the service that is returned in the requesting bundle is a singleton. At times I notice a threading issue since it is a "stateful" service. How do I configure the application to get back a new service instance with each call?

Here is my spring xml file contents which registers the service:

<bean id="myServBean" class="com.xyz.ClassImpl"/>
<osgi:service ref="myServBean" class="com.xyz.Class"/>
A: 

OSGi services in general can be called concurrently by multiple clients. The only thing OSGi supports out of the box is the use of a ServiceFactory, which allows you to return a different instance to each invoking client bundle. There is no standard mechanism to create a new instance per method call. You would have to handle that in your service implementation yourself.

Marcel Offermans
Thanks, that is also what I have read about in other places and wanted to confirm.
Bhav