hi
i have a program
which has two synchronized methods.
but both make a call to same non synchronized method.
this non synchronized method makes changes to the list of data that i have.
is it thread safe??
synchronized method1(obj o1){
//some other data
makeFirst(o1)
}
synchronized method2(obj o2){
//some other data
makeFirst(o2)
}
makeFirst()
{
makes changes to same list of data
}
printdata()
{iterate over list and print values
}
do i need to make 'makechange() and printdata()' methods synchronized as well ???
makeFirst is a private method...which is just called by these two methods.
while the PrintData is called publicly.
wouldnt i require to synchronize this makeFirst method because at a time when both synchronized methods will be calling this method.
the two different threads may each may be calling one of the methods
like
Thread1 calls synchronized method1
Thread2 calls synchronized method2
but these two methods call the makeFirst method. wihch is accessing the same list of data.
there is nothign that is synchronizing access to the makeFirst method.
ie. nothing is making these two calls from two threads to be synchronized.
just a psuedocode below.
thread1.synchronized method1.makeFirst()
thread2.synchronized method2.makeFirst()
both sharing same data and making changes to it..
but if i make makeFirst as synchronized, it will make only one of these methods to access the data and make changes to the list at one instance of time.
Am i thinking on the right way.?