Dear All
I have a class whose methods are getting called from multiple threads in my
application.
For example
class DataDistributio n
{
private ArrayList datset;
public DataDistributio n()
{
this.datset = new ArrayList();
}
public void SetData ( int x, IAssignable data )
{
ArrayList synchronizedLis t = ArrayList.Synch ronized(this.da taset);
(synchronizedLi st [x] as IAssignable ).Assign ( data );
}
public IAssignable GetData( int x )
{
ArrayList synchronizedLis t = ArrayList.Synch ronized(this.da taset);
return (this.synchroni zedList [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 DataDistributio n
{
private ArrayList datset;
public DataDistributio n()
{
ArrayList tmpList = new ArrayList();
this.datset = ArrayList.Synch ronized ( 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