Re: singleton - hashmap references
"Shash Chatterjee" <[email protected]> Wed, 11 Aug 2004 14:14:17 -0600
| Newsgroups | gmane.comp.java.keel.user |
|---|---|
| Message-ID | <[email protected]> |
Vince,
> What is the preferred method to create a singleton class that is
> instantiated when the application is initialized but whose methods,
> or variables,
> (in my case static hashMap lookups) are available to all models
> within an application.
>
- For the container to return the same singleton component instance every time
the component is looked up, in your (thread-safe) implementation class's
meta-data, you should have:
* @x-avalon.lifestyle type=singleton
- For the container to instantiate this component when the container starts
up, in the component's configuration set activation as "startup":
<my-component id="myapp.mycomponent" activation="startup">
<other-config>
</other-config>
</my-component>
- For initialization of the class when it is instantiated, unless you want
lazy initialization, implement the Initializable interface. The container
will call the initialize() method when the component is first created
HTH,
Shash