@Override
 public void run() {
   while (!stop) {
     ServiceObjects<String> serviceObjects = ctx.getServiceObjects(ref);
     try {
       String svc = serviceObjects.getService();
       if (!"bar".equals(svc)) System.out.println("Bad Service!");
       else counter++;
       //                serviceObjects.ungetService(svc);
     } finally {
       ctx.ungetService(ref);
     }
   }
   System.out.println("Thread done (" + getClass().getSimpleName() + ")");
 }
 /**
  * Returns a service object for the {@link #getServiceReference() associated} service.
  *
  * @see org.osgi.framework.ServiceObjects#getService()
  */
 public S getService() {
   synchronized (rls) {
     if (cci.cc.getState() == ComponentConfiguration.STATE_DEACTIVE) {
       throw new IllegalStateException("Reference unbound");
     }
     if (rls.isEmpty()) {
       return null;
     }
   }
   S service = so.getService();
   synchronized (rls) {
     Integer refCnt = services.get(service);
     refCnt = new Integer(refCnt != null ? refCnt.intValue() + 1 : 1);
     services.put(service, refCnt);
   }
   return service;
 }