摘要: 一、模拟线程不安全场景。 public class MyRunnable implements Runnable { private int a = 100; //共享的数据 @Override public void run() { while (true) { if (a > 0) { //多个 阅读全文
posted @ 2021-09-02 15:52 饮木 阅读(48) 评论(0) 推荐(0) 编辑
摘要: Thread类实现多线程。 一、创建多线程实现类。 public class MyThread extends Thread { //继承Thread类 public MyThread() { } public MyThread(String name) { //通过构造函数设置线程名称 super 阅读全文
posted @ 2021-09-02 10:37 饮木 阅读(38) 评论(0) 推荐(0) 编辑