Hi!

Michael Lepine wrote:
> I simply want a single instance of an object which can be found via JNDI and
> used globally throughout the application.
> For example, a logging class that can be used to write to a log on a
> particular file system. Only one instance should ever exist to maintain the
> integrity of the data written to the log (would have one instance variable
> of type OutputStream or PrintStream that is used to write to the file
> system).

Well, logging is not a good example, since that would typically be done
through the jBoss server. jBoss allows you to log all bean invocations,
and if you do System.out.println's these will be redirected to the
server logging system, which you can attach a filter to log bean output
to a file. No coding involved.

> Another example would be a simple class that contains one instance variable,
> uniqueId, of type int and the sole purpose of this class is to increment and
> return a unique id or value when requested.

For these purposes we have a special singleton pool for stateless
session beans. Make a stateless session bean, and choose the singleton
container configuration for it. jBoss will only create one instance of
this bean, which you can use for id's.

> I think these classes are required since I cannot make things static in a
> distributed computing environment, which EJB is intended to facilitate. Is
> this right, or is it that I just cannot use static in classes that are
> intended to be beans (I think it is the former, but hearing it is the latter
> would make things easier)?

The static restrictions is more to not allow you to shoot yourself, than
a security measure. Since bean classes can be replaced at any point in
time (specifically at redeploy in jBoss), hence resetting statics, you
shouldn't use that. The same applies to the above, where the singleton
will be reset upon redeploy. There's no free lunch, but you get the
dessert for free ;-)

Does this answer your query?

/Rickard

-- 
Rickard �berg

@home: +46 13 177937
Email: [EMAIL PROTECTED]
http://www.telkel.com
http://www.jboss.org
http://www.dreambean.com


--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to