Results 1 to 2 of 2
Thread: Synchronized block in java
- 12-12-2012, 10:53 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 5
- Rep Power
- 0
Synchronized block in java
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.Java Code:Class table { Synchronized(this) { …………………… } }
--------------------------------------…
Part2:
Here we got lock on object of customer.i.e on custJava Code:Class 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
- 12-12-2012, 12:34 PM #2
Re: Synchronized block in java
Please see my responses at #2 and #5 in your previous thread: doubt on synchronized block in java
Any more multiposting and you will be banned for a period. There will be no further warning.
db
THREAD CLOSEDWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
doubt on synchronized block in java
By me_shankara in forum Threads and SynchronizationReplies: 6Last Post: 12-20-2012, 12:38 PM -
calling yield() method in synchronized block
By Ash-infinity in forum New To JavaReplies: 2Last Post: 12-04-2012, 05:35 PM -
IllegalMonitorStateException from synchronized block
By svdeepha in forum Threads and SynchronizationReplies: 1Last Post: 04-26-2010, 07:32 PM -
Return in the Middle of synchronized Block
By ariak in forum Advanced JavaReplies: 1Last Post: 07-26-2007, 10:24 AM


LinkBack URL
About LinkBacks

Bookmarks