Singleton Pattern in ATG

View: New views
5 Messages — Rating Filter:   Alert me  

Singleton Pattern in ATG

by Mani ATG :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How Singleton Pattern can be implemented for ATG Component?
(I know J2EE implementation of Singleton pattern.Same approach cannot be used for ATG env)
 
Thanks in advance.
 
Mani Raju

Re: Singleton Pattern in ATG

by MJL :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Perhaps you could explain what you're trying to do and what problem you think you're having.

Globally scoped Nucleus components are singletons by definition, for example.

Re: Singleton Pattern in ATG

by Mani ATG :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I dont have issues, just for practice.

I agree, global scoped component maintains single instance over the session.
Can we use following to maintain singleton:

create nucleus component with public void synchronized constructor.

Re: Singleton Pattern in ATG

by george_o :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mani,
  Your understanding of session and global scopes appears to be incorrect. Global scoped components are shared by all sessions, and definitely not "maintains single instance over the session" as you stated.

When you define a global scoped component, there will only be one instance of that object in the entire JVM (unless you create the actual object via Java code, i.e. new CustomComponentClass() since that bypasses the ATG Nucleus framework). As long as you are using component references, Nucleus will ensure that only a single instance of that global scoped component will exist at any one time.

- George

Re: Singleton Pattern in ATG

by Thiyagarajan Muthusamy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hope making an ATG component of global scope would serve the purpose of Singleton pattern