Hi Do not think I am asking repeated question.As I could not express my doubt clearly once again i am sending.
-------------------------------------------------------------------------------------------------------------
Part1
--------------:
Here we got lock on object of table class.Class table { Synchronized(this) { …………………… } }
--------------------------------------…
Part2:
Here we got lock on object of customer.i.e on custClass table { Customer cust=new Customer(); Synchronized(cust) { …………………… } }
- table class.In part1 we got lock on object of
We get lock on table class because object of table class may try to access the synchronized block from different places simultaneously.To prevent it we got lock on object of table class in part1.
-Now come to part2:
Here we got lock on object of customer class
--------------------------------------…
My doubts:
1)why should we lock an object in table class other than table class in part2?
2)2)If we do not get lock on cust in part 2 then we can access synchronized block using table class
If we lock cust then also we need object of table class to access synchronized block.
Object of table class only needed to access synchronized block.
Due to synchronization we prevented object of table class to access synchronized block simultaneously from different threads.
Then why should we lock object other than table class in table class?
3)Will object of customer class try to access the synchronized block simultaneously from different places?
4).In part2 we got lock on object other than table class.
In What situations getting lock in table class on an object of a class other than table is benefit of getting lock on object of customer class in part2?
5)What is the need to lock object of customer class i.e other than table class?
6)What damage will happen if we do not get lock on object of customer class in part2?
--------------------------------------…
I think meaning of all questions is same.But I expressed doubts as I got.
I hope you answer