Synchronize it?
Hi all,
okey here is the deal :P
class List
{
Hashtable data;
....
public void add(String key, String text)
{
data.put(key, text);
}
public void remove(String key)
{
data.remove(key);
}
}
Methods in hashtable are synchronized, so data will be locked if add is called in the List, but the List object it self will not be locked right? So if another thread calls remove it will not be blocked on List but on data (if another thread is busy with it), so that's still safe right?
If learned that an object can be seen as a plane with a bathroom. When threads (people who want access to the bathroom) want to access it, they check if it's locked, if it's locked they wait in line or else they go inside and lock it for themselfs.
so in this case data is the plane, but what happends if I also synchronize the methods in List. Will the then become an plane that bigger then the other plane with the smaller plane inside of it?
And what happends if I extend List with another class and do I have to Synchronize methods in that class as well and will this be a performace loss?
Thnx in advance
David

