How can I ensure that an overridden method is synchronized

前端 未结 3 447
傲寒
傲寒 2021-02-02 09:59

I have a class of common code that is thread safe.

One of the methods in that class is abstract and needs to be overridden for different implementations.

I need

3条回答
  •  盖世英雄少女心
    2021-02-02 10:47

    From Synchronized method in subclass

    Synchronized is the implemenation detail of a method. You can override a sync method with a method without declaring that as sync and vice versa. The same holds true for the overloading also.

    You can also have a look at, A synchronized method in the superclass acquires the same lock as one in the subclass.

提交回复
热议问题