[jboss-osgi-issues] [JBoss JIRA] Commented: (JBOSGI-479) Race condition when registering services in multiple threads

Thomas Diesler (JIRA) jira-events at lists.jboss.org
Mon Jul 18 04:16:23 EDT 2011


    [ https://issues.jboss.org/browse/JBOSGI-479?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12614705#comment-12614705 ] 

Thomas Diesler commented on JBOSGI-479:
---------------------------------------

Yes, I understand all that and I'm not suggesting that the client should deal with the failure. Instead I was suggesting something like this

{code}
    try {
        ServiceBuilder<List<ServiceState>> builder = serviceTarget.addService(serviceName, service);
        builder.install();
    } catch (DuplicateServiceException ex) {
        controller = (ServiceController<List<ServiceState>>) serviceContainer.getService(serviceName);
        controller.getValue().add(serviceState);
    }
{code}

which avoids synchronization and canonical name computation

http://www.ibm.com/developerworks/java/library/j-threads1/index.html#h15733

Anyway, assumption aside. The performance impact can easily be measured and you might be right that it is negligible.  

> Race condition when registering services in multiple threads
> ------------------------------------------------------------
>
>                 Key: JBOSGI-479
>                 URL: https://issues.jboss.org/browse/JBOSGI-479
>             Project: JBoss OSGi
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>            Reporter: David Bosschaert
>            Assignee: David Bosschaert
>
> When registering multiple services with the same service name a race condition occurs. This is exposed when running the Service Performance tests (e.g. org.jboss.osgi.test.performance.service.arq.Service100TestCase).
> The problem boils down to the fact that two threads race to obtain a service controller for the same name. One of them wins, the other fails with this exception:
> org.jboss.msc.service.DuplicateServiceException: Service jbosgi.service."org.jboss.osgi.test.performance.service.SvcCls1" is already registered
> 	at org.jboss.msc.service.ServiceRegistrationImpl.setInstance(ServiceRegistrationImpl.java:154)
> 	at org.jboss.msc.service.ServiceControllerImpl.startInstallation(ServiceControllerImpl.java:226)
> 	at org.jboss.msc.service.ServiceContainerImpl.install(ServiceContainerImpl.java:560)
> 	at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:201)
> 	at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2194)
> 	at org.jboss.msc.service.ServiceBuilderImpl.install(ServiceBuilderImpl.java:307)
> 	at org.jboss.osgi.framework.internal.ServiceManagerPlugin.registerService(ServiceManagerPlugin.java:180)
> 	at org.jboss.osgi.framework.internal.AbstractBundleContext.registerService(AbstractBundleContext.java:305)
> 	at org.jboss.osgi.framework.internal.AbstractBundleContext.registerService(AbstractBundleContext.java:297)
> 	at org.jboss.osgi.test.performance.service.CreateAndLookupBenchmark.runThread(CreateAndLookupBenchmark.java:79)
> 	at org.jboss.osgi.test.performance.service.CreateAndLookupBenchmark.runThread(CreateAndLookupBenchmark.java:41)
> 	at org.jboss.osgi.test.performance.AbstractThreadedBenchmark$1.run(AbstractThreadedBenchmark.java:91)
> 	at java.lang.Thread.run(Thread.java:680)

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-osgi-issues mailing list