• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt on Synchronized block

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic