• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
mamidi venkat
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

What is the difference between Synchronized Block and Synchronized method with an example .confused with this.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following two are the same:

Do you now understand what it means if you make a method synchronized?
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With a synchronized block you can choose to only synchronize part of the code in the method. With a synchronized method, all the code in the method is synchronized.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And with a synchronized block you can choose what to synchronize on. With a synchronized method, an instance method always synchronizes on the instance, a static method always synchronizes on the class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic