Thursday, July 8, 2010

PDE Good Practices: #3 Lazy-loading and Singleton plug-ins

Lazy Loading

When a plug-in is marked for lazy loading it is NOT loaded until it is needed. This helps in keeping the memory footprint of application small as possible.

A plug-in can be marked for lazy loading by checking the 'Activate this plug-in when one of its classes is loaded' checkbox on the Manifest editor overview page. This create the following entry in the Manifest.MF file.

Bundle-ActivationPolicy: lazy

Singleton plug-ins

It is preferable to use singleton plug-ins unless you know what you are doing. If a plug-in exposes extension points then it has to be singleton. But if not, it is still advisable to keep them singleton. This would ensure only one version of the plug-in is loaded at a time and generally its the latest one (unless version bound).

A plug-in can be made singleton by checking the 'This plug-in is a singleton" checkbox on the manifest editor overview page.

OSGi environments generally prefer non-singleton plug-ins as they can be dynamically installed.