Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

locks

 
josephine chen
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check my answers
Which of the following have locks
only threads //t
classes have locks //t when u have sync methods
primitive types have locks //f
only runnable objects //t
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
only threads //only makes the ans NO. (threads also have locks since all objects have locks)
classes have locks //t when u have sync static methods
primitive types have locks //f
only runnable objects //t NO[/b]
maha anna

[This message has been edited by maha anna (edited February 20, 2000).]
[This message has been edited by maha anna (edited February 20, 2000).]
 
josephine chen
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as such runnable obj have locks becoz he said only
it is no
Am i right mahaAnna!!!
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes Shan. your reason is right.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi maha,
1)only threads //only makes the ans NO. (threads also have locks since all objects have locks)
2)only runnable objects //t NO[/b]
could you clarify on the above two points
 
Marcela Blei
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A field declared volatile isn�t locked?
I read from the JLS: a thread must reconcile its working copy of the field with the master copy every time it accesses the variable.
This means lock or a behavior like lock, isn�t it?
 
Savithri Devaraj
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by maha anna:
only threads //[b]only makes the ans NO. (threads also have locks since all objects have locks)
classes have locks //t when u have sync static methods
Why static?
primitive types have locks //f
only runnable objects //t NO[/b]
maha anna

[This message has been edited by maha anna (edited February 20, 2000).]
[This message has been edited by maha anna (edited February 20, 2000).][/B]

Is n't it that all objects can have locks ? Primitives are not objects, hence can't be locked.
Savithri
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic