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. 

regards, 

        Gunnar


------------------------------------------------------------
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