Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] is a bundle equal to a java thread


Don't get hung up on threading... the OSGi framework does not create a thread per bundle, per BundleContext, or per registered/acquired service.  A service is not inherently "active", it is simply an object that has been registered with the OSGi framework's registry using a well defined key that is a Java type, most typically an interface.  Of course, multiple threads could access a service object concurrently, so it is the responsibility of the bundle that registers the service to implement the appropriate synchronization/locking strategy to protect the integrity of the service.  If a service needs to be "active" then it should be implemented using one or more threads.  An OSGi service object is really no different from any other POJO.



"Kenny Su" <kennysu.tw@xxxxxxxxx>
Sent by: equinox-dev-bounces@xxxxxxxxxxx

08/28/2006 01:20 AM

Please respond to
Equinox development mailing list <equinox-dev@xxxxxxxxxxx>

To
"Equinox development mailing list" <equinox-dev@xxxxxxxxxxx>
cc
Subject
Re: [equinox-dev] is a bundle equal to a java thread





Thanks for the replies.
So there is only one thread from framework to handle the bundles' start-up, and when
bundles be started, there is no new threads be created.
But how OSGi framework provides so many bundles services which can be accessed
simultaneously ? or framework creates a thread for each BundleContext ?

Thanks again.
Kenny
 
On 8/27/06, Simon J Archer <sarcher@xxxxxxxxxx> wrote:

Kenny


Bundles are started on a thread that is owned by the OSGi framework, so it is important that your BundleActivator (which is optional) returns from start(BundleContext) and stop(BundleContext) as quickly as possible. Most bundles start quickly enough that they don't need to spawn their own thread, but spawning your own thread is not out of the question.  With regards to stop(BundleContext), the bundle must stop and clean up all its resource before returning.  This obviously means that you can't spawn a new thread to perform stop!


Regards


Simon



Marcel Offermans <marcel.offermans@xxxxxxxxxx >
Sent by:
equinox-dev-bounces@xxxxxxxxxxx

08/26/2006 12:56 PM

Please respond to
Equinox development mailing list <
equinox-dev@xxxxxxxxxxx>


To
Equinox development mailing list <equinox-dev@xxxxxxxxxxx>
cc
Subject
Re: [equinox-dev] is a bundle equal to a java thread






Hello Kenny,

On Aug 26, 2006, at 18:48 , Kenny Su wrote:

> I am just getting starting with OSGI and new to here.
> When a bundle be started by framework, does it mean starting
> a java thread or more java threads ?

No, when a bundle is started, no new thread is created.

When you create a bundle that contains a BundleActivator, the  
framework will invoke the start() method when your bundle is started.

It is not uncommon for a bundle to spawn a thread itself (in the start
() method). Make sure you clean it up again in the stop() method.

Greetings, Marcel


_______________________________________________
equinox-dev mailing list

equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev


_______________________________________________
equinox-dev mailing list

equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev


_______________________________________________
equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev


Back to the top