File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Synchronized

 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why we cannot declare a method as abstract and synchronized?
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because its better not to do it since its better to synchronize your code at block levels instead of making the whole method as synchronized, however note that when you define a concrete implmentation of the method you can specify that its synchronized.

(peace)
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to make it more clear, if you have an abstract method, then while overriding you can add the synchronized keyword to the method. And if a method is synchronized (non-abstract method of course), then while overriding it, you can remove the synchronized keyword. So there's no point in making an abstract method synchronized as the overriding code can add or remove the synchronized keyword on will. This behavior of the synchronized keyword is because synchronized is not a part of method signature...
 
Prav sharma
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rightly said. SYnchronised is not a part of the method signature.

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether a method needs to be synchronized or not, depends on how that method is implemented.

Since an abstract method has no implementation at all, it doesn't make sense to make it synchronized.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic