title: OSGi Declarative Services in Eclipse, multiple service interfaces, and Thread Safety
body: <p>I just stumbled over a phenomenon in my code which comes down to this:</p>
  
  <p>I have an OSGi Declarative Service providing two service interfaces configured as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="init" deactivate="dispose" enabled="true" name="redacted.redactedstore"&gt;
     &lt;implementation class="redacted.RedactedStore"/&gt;
     &lt;service&gt;
        &lt;provide interface="redacted.IRedactedStore"/&gt;
        &lt;provide interface="redacted.IRedactedStoreControl"/&gt;
     &lt;/service&gt;
  &lt;/scr:component&gt;
  </code></pre>
  
  <p>In my code, I have two different threads which both open a <code>ServiceTracker</code> to get the service instance, but via different interfaces:</p>
  
  <pre><code>tracker = new ServiceTracker&lt;&gt;(getBundle().getBundleContext(), &lt;serviceClass&gt;.class, null);
  tracker.open();
  tracker.waitForService(1000l);
  </code></pre>
  
  <p>So one thread uses <code>IRedactedStore</code> as service class and the other uses <code>IRedactedStoreControl</code> as service interface.</p>
  
  <p>So what seems to happen is that when both threads run in parallel at the right time, the Equinox SCR will instantiate not one (as I would expect) but two instances of the component implementation class.</p>
  
  <p>Is this behavior correct? Or is this a bug in the Equinox implementation of OSGi?</p>
  
  <p>If the behavior is correct, can I do something in my code to prevent that by configuring the service another way? (of course I could restructure the service so it only provides one interface, or I could synchronize the service trackers...)</p>