[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [equinox-dev] my confusion for unregistering services in bundle.stop
- From: Thomas Watson <tjwatson@xxxxxxxxxx>
- Date: Mon, 31 Mar 2008 08:04:10 -0500
- Delivered-to: firstname.lastname@example.org
It is more clear to clean up your service registrations and service listeners in your BundleActivator.stop method. In many cases you want to unregister your listeners and services before you do other clean-up that will invalidate the services/listeners and cause them to behave incorrectly. For example, closing a database connection that backs a service implementation. You should unregister the service before closing the database connection.
The extra cleanup the Framework does is really a safeguard to prevent invalid services and listeners from collecting in the Framework.
Meng Xin Zhu ---03/31/2008 05:17:51 AM---I find below description in the OSGi R4 specification section '4.3.6 Activation':
Meng Xin Zhu <zhumx@xxxxxxxxxx>
Xiang Yu Hao <haoxy@xxxxxxxxxx>
03/31/2008 05:17 AM
[equinox-dev] my confusion for unregistering services in bundle.stop
I find below description in the OSGi R4 specification section '4.3.6 Activation':
stop(BundleContext) â This method must undo all the actions of the BundleActivator.start(BundleContext) method. However, it is unnecessary to unregister services or Framework listeners, because they must be cleaned up by the Framework anyway.
Recently I read a post introducing development best practices(it's ibm internal site), it says:
While the OSGi Framework will clean up services and service references, it is still good programming practice to clean up what you allocate.
If you register services in the start() method, unregister the services in the stop() method.
If you create (and open) a ServiceTracker in the start() method, close it in the stop() method.
If you start threads or jobs in your start() method, make sure that the threads or jobs are terminated by your stop method.
Which practice I would choice when programming OSGi service under Equinox? Thanks
Zhu Meng Xin
IBM Workplace Client Technology
Tel: 86-10-82452244-52342 Fax: 86-10-82452887
NOTES: Meng Xin Zhu/China/IBM E-mail: zhumx@xxxxxxxxxx_______________________________________________
equinox-dev mailing list