• 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 in Threading

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks.I have a simple doubt in threading.From the threading chapter I see that "Only methods can be synchronized".Later in the chapter I saw "Synchronized" being used on Objects and blocks of code.Doesnt that mean Synchronized can be used on Reference variables(object) as well?

Thanks.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Only methods can be synchronized".Later in the chapter I saw "Synchronized" being used on Objects and blocks of code.Doesnt that mean Synchronized can be used on Reference variables(object) as well?



when you synchronize a method or block you are actually obtaining a lock on that object..

Doesnt that mean Synchronized can be used on Reference variables(object) as well?


what actually book meant was you cannot write like::
private synchronized int a = 6;
private synchronized String s = "JavaRanch" ;


you can only use the synchronized kryword either with a method or a block...
 
Rahul Siddharth
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Priyam.Appreciate it.
reply
    Bookmark Topic Watch Topic
  • New Topic