dcsimg
Pattern for sharing a object within a thread?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Izabela_Sremac
Posted On:   Monday, November 26, 2001 04:20 PM

I'm new to patterns so help here is greatelly appreciated!:)


We have an object that is created and populated for each new thread running and used by multiple DAO's (Data Access Objects) run in that thread. What would be a good pattern to use for sharing this object between multiple DAO's (but not pass it into each DAO call that needs to use it). Note: This shared object is thread specific. Thanks!!

Re: Pattern for sharing a object within a thread?

Posted By:   Anonymous  
Posted On:   Tuesday, November 27, 2001 01:11 AM

Sharing a single object without passing it around sounds like the singleton pattern for me. You might use the ThreadLocal class to make it thread specific.

Re: Pattern for sharing a object within a thread?

Posted By:   John_Austin  
Posted On:   Monday, November 26, 2001 08:57 PM

This is not a pattern solution, but I think the usual approach is to create
this object as a private synchronized object inside your class that implements Runnable (and therefore runs on a thread).

This will allow a single thread access
to the object at any time.

Your question could be more precise as there is some ambiguity in my mind as to whether the DAO's are on a single thread or are they on other threads.
About | Sitemap | Contact