• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on Synchronized block

 
Dinesh Tahiliani
Ranch Hand
Posts: 486
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ian Edwards
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic