Dear All
I have a class whose methods are getting called from multiple threads in my
application.
For example
class DataDistribution
{
private ArrayList datset;
public DataDistribution()
{
this.datset = new ArrayList();
}
public void SetData ( int x, IAssignable data )
{
ArrayList synchronizedList = ArrayList.Synchronized(this.dataset);
(synchronizedList [x] as IAssignable ).Assign ( data );
}
public IAssignable GetData( int x )
{
ArrayList synchronizedList = ArrayList.Synchronized(this.dataset);
return (this.synchronizedList [x] as IAssignable ).;
}
}
These two methods are being called from two different threads.
I'm just planning to modify the above class definition as shown below to
avoid calling Synchronized on array list every time.
class DataDistribution
{
private ArrayList datset;
public DataDistribution()
{
ArrayList tmpList = new ArrayList();
this.datset = ArrayList.Synchronized ( tmpList );
}
public void SetData ( int x, IAssignable data )
{
(this.datset [x] as IAssignable ).Assign ( data );
}
public IAssignable GetData( int x )
{
return (this.dataset[x] as IAssignable ).;
}
}
Can anybody suggest me what are the advantages & disadvantages with these
two approaches?
Tons of thanks in advance.
Regards
Krishna