Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock on Objects

 
Seth Anshul
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does each Object in Java has a corresponding lock?
 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The lock field in the Object class is for multi-threaded programming. Using an object's lock is sometimes necessary to keep data from becoming corrupted when there are multiple threads sharing the same objects.

I consider multi-threading to be a fairly advanced aspect of Java.

http://java.sun.com/docs/books/jls/second_edition/html/memory.doc.html
[ February 19, 2008: Message edited by: Kaydell Leavitt ]
 
Seth Anshul
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kaydell.

Ulf, multiple post was not the intention.My net connection broke, thus leading to it.

Asset :roll:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic