This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt on Synchronized block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt on Synchronized block" Watch "Doubt on Synchronized block" New topic
Author

Doubt on Synchronized block

Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
Hello Ranchers,

Need your help to understand this.


What is difference between line1, line 2 and line 3.
Line 2 is giving me the error. Can you tell me why its?

Thanks
Dinesh


[BSouther: Added UBB CODE tags]
[ February 21, 2008: Message edited by: Ben Souther ]

Thanks<br />Dinesh
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Can you please paste your code using [code] tag, It is really very difficult to understand the code..!! need more time..!!

all I understood from your code is that:

Line 1: Class level lock --> It is good when we have multiple threads running on different instance.
------------------------------------------

Line 2: Locking nothing --> compiler Error
------------------------------------------

Line 3: Object Level Lock --> It is good when we have multiple thread running on same instance.


Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
Ian Edwards
Ranch Hand

Joined: Aug 14, 2006
Posts: 107
You have a syntax error at line 2. You are using the synchronized keyword but not telling it which object you want to synchronize on. You want to use something like you have at line 1.
 
 
subject: Doubt on Synchronized block
 
Similar Threads
abstract class and static methods
Advanced overloading
a little confirmation required about threads and synchronization
Method overloading
Doubt in inner class