Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Can Constructor be synchronized? Why?

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


I have the above mock question, and it cannot compile?

So constructor cannot be synchronized. But why not? Since it cannotsynchronize object - this, or cannot synchronize Object -Class?

Can anyone explain for me? Thank you!
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Consider this code. The idea of synchronizing is to ensure that,
two threads, say t1 and t1, do not execute the save method on an instance
of this class, at the same time.

No think if this requirement holds for a constructor. At construction time,
is there possibility of a conflict as described above? And you will have the answer.

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


At construction time,
is there possibility of a conflict as described above?



In case if two threads are calling one method to instantiate the class is it guaranteed that it wont overlap. In other words, does constructor complete atomically, no overlapping like thing. As I guess, if overlapping does, it wont affect each other, each time new instance will be created; so for that instance the constructor code will be running.


I am specially concerned about Singleton pattern. get an instance of the class from the static method. there will be one and only object created of that class.

I am little puzzled!

Focus some ray of light here!


cmbhatt
[ April 10, 2007: Message edited by: Chandra Bhatt ]
 
What's wrong? Where are you going? Stop! Read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic