3

I have a derived class, and for some reason, I have to make two methods of this class synchronized to prevent them executing at the same time. One of the methods is an overridden method. Parent method is not synchronized.

Is it ok to synchronize the overridden method?

Lahiru Chandima
  • 22,324
  • 22
  • 103
  • 179

1 Answers1

3

Look here: https://stackoverflow.com/a/15998431/5226711

synchronized is not part of the method signature.

So it is okay to synchronize the overridden method.

Community
  • 1
  • 1
Lars Gendner
  • 1,816
  • 2
  • 14
  • 24
  • 5
    There is a difference between being able to do something and doing something which is best practice. – Tim Biegeleisen Sep 01 '15 at 01:06
  • Your answer, which is correct, is saying that it is _possible_ to override a method and add `synchronized`. But this does not necessarily mean that we _should_ be doing this. – Tim Biegeleisen Sep 01 '15 at 01:39
  • 2
    Depends on the situation, doesn't it? Since the question does not describe the concrete circumstances, it can well be the case that OP has motivation for synchronization in a subclass. – Lars Gendner Sep 01 '15 at 21:39