Gunnar R|nning wrote:
> 
> John & Kristen McNally <[EMAIL PROTECTED]> writes:
> 
> >
> > This analysis assumed (wrongly, from the recent discussion) a Hashtable
> > was thread-safe.
> 
> The Hashtable is thread safe. But you can still cerate unsafe programs
> around something safe.
> 
> >
> > I still hate to add the inefficiency if it is not necessary, but maybe
> > it should be added until it is absolutely determined to be safe.
> 
> >From Paul example it seems you can use a pretty standard pattern, so you
> only perform synchronization when you really need to :
> 
> static Hashtable myobjects = new Hashtable();
> 
> public MyObject getMyObject(String name){
>         MyObject mo = (MyObject) myobjects.get(name);
>         if(mo == null){
>                 synchronized(myobjects){
>                         mo = (MyObject) myobjects.get(name);
>                         if(mo == null){
>                                 mo = new MyObject(name);
>                                 myobjects.put(name, mo);
>                         }
>                 }
>         }
> }
> 
> But since Turbine is going 1.2 you might want to start using the HashMap
> class, since this does no synchronization at all.

Correct.  Since the above pattern is necessary in the majority of the
places where Hashtable is used, we will be providing our own
synchronization and therefor would not almost need the synchronization
provided by Hashtable.
-- 

Daniel Rall <[EMAIL PROTECTED]>


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to