You're absolutely correct. I oversimplified my use case and made one that
worked. Below is what I'm really trying to do, and I verified it does
deadlock this time. I'm trying to make a safe wrapper around BundleActivator
that makes sure developers don't block in the start() method indefinitely so
we can more quickly diagnose problems during development...


public final static long bundleStartupTimeoutInSeconds = 15;

public void start(final BundleContext bundleContext) throws Exception
{
        final Semaphore bundleStartedSemaphore = new Semaphore(1);
        bundleStartedSemaphore.acquire();
            
        Thread bundleStartupThread = new Thread(new Runnable(){
            public void run()
            {
                try
                {
                    Hashtable properties = new Hashtable();
                    properties.put(Constants.SERVICE_PID,"foo.bar");
                    bundleContext.registerService(Integer.class.getName(),
new Integer(4) , properties);

                    bundleStartedSemaphore.release();
                }
                catch(Throwable t)
                {
                    t.printStackTrace();
                }
            }
        });

        bundleStartupThread.start();

        if(!bundleStartedSemaphore.tryAcquire(bundleStartupTimeoutInSeconds,
TimeUnit.SECONDS))
        {
            bundleStartupThread.interrupt();
            
            String message =
                "Bundle start-up timeout exceeded
("+bundleStartupTimeoutInSeconds+" secs) " +
                "when starting bundle
'"+bundleContext.getBundle().getSymbolicName()+"'.";
            
            throw new TimeoutException(message);
        }
}
-- 
View this message in context: 
http://www.nabble.com/Deadlock-registering-service-tp23947039p23949183.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to