how to write a singleton in JavaEE

We have a DataCollector which collects and stores data periodically. So this class should have only one instance (or else data will be duplicated in the DB).Anyone any idea?
[187 byte] By [revevera] at [2007-11-27 7:40:51]
# 1

> We have a DataCollector which collects and stores

> data periodically. So this class should have only one

> instance (or else data will be duplicated in the

> DB).

>

> Anyone any idea?

google "Java Singleton" and you should get three methods of creating a singleton.

r035198xa at 2007-7-12 19:21:24 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Try following which is very comprehensive article on Singleton. http://javatouch.googlepages.com/singletonpattern
nalakayoyoa at 2007-7-12 19:21:24 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Be careful with singletons.

They tend to be non-scalable (doesn't work in a load balanced environment, not without special care), and are usually a horrible source of trouble for garbage collectors (they tend to collect huge amounts of data and GC's need some time to sweep through) causing temporary noticeable web application freezes.

Why not just working in the regular EJB/3 domain?

jdesmeta at 2007-7-12 19:21:24 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...