• Post Reply Bookmark Topic Watch Topic
  • New Topic

static methods  RSS feed

 
p hasini
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens when a method is declared as both synchronized and static.
 
Vijitha Kumara
Bartender
Posts: 4002
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
p hl wrote:What happens when a method is declared as both synchronized and static.

Nothing happens doing so until two threads tries to access the method at the same time, then one will have to wait until the other finishes.
 
Embla Tingeling
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
p hasini wrote:What happens when a method is declared as both synchronized and static.


When a non-static synchronized method is called the lock is held by the object.

When a static synchronized method is called the lock is held by the class (or rather the object representing the class at runtime).

 
p hasini
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!