Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

synchronized constructors

 
Vidyasagar Guduru
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we use a synchronized constructor like below, compiler will not agree.



but using a synchronized block is legal




Why the compiler is allowing the second one and not the first one.
[ December 18, 2006: Message edited by: Vidyasagar Guduru ]
 
Bipin Velkur
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the language feature. The reason why this limitation is placed is because:

Two threads that call the same constructor concurrently operate on two distinct pieces of memory for two distinct instances of the same class.

If there is a mutually shared resource, you must synchronize on that resource in order to avoid conflicts.

Hope this clears the thing up.
 
Bipin Velkur
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just did a google and here is an article if you want to read more about it:

http://www-128.ibm.com/developerworks/java/library/j-praxis/pr46.html


P.S: Parts of my post were taken from this article
 
Andrea Z�rcher
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this: web page
 
Vidyasagar Guduru
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the links.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic