1.10 模拟子类Son的同步方法调用父类Father的同步方法

/**
 * This is description.
 * 模拟子类Son的同步方法调用父类Father的同步方法.
 *
 * @author Chris Lee
 * @date 2019/3/2 20:30
 */
public class Father {

    /**
     * 父类Father的同步方法fun().
     */
    public synchronized void fun() {
        System.out.println("Father start.");

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("Father end.");
    }

    public static void main(String[] args) {
        Son son = new Son();
        new Thread(() -> son.fun()).start();

        /*
            Son start.
            Father start.
            Father end.
            Son end.
         */
    }

}
说明:
  • 本篇文章如有不正确或待改进的地方, 欢迎批评和指正, 大家一同进步, 谢谢!
  • 世上有4样东西可以让世界变得更美好, 它们是: 代码(Code), 诗(Poem), 音乐(Music), 爱(Love). 如有兴趣了解更多, 欢迎光顾"我的文集"相关文章.
资料:
  1. 学习视频: https://www.bilibili.com/video/av11076511/?p=1
  2. 参考代码: https://github.com/EduMoral/edu/tree/master/concurrent/src/yxxy
  3. 我的代码: https://github.com/ChrisLeejing/learn_concurrency.git
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容