javaSE
多线程的学习
程序 跑起来就是 进程 进程运行的是一个个 线程 其实线程就是我们所写的main就是主线程
- 自定义线程类继承Thread类
- 重写run()方法,编写线程执行体
- 创建线程对象,调用start()方法启动线程
接下来用一张图来解释一下run和start的区别
创建线程方法方式一: 继承Thread类,重写run()方法,调用start开启线程
创建线程方法方式二: 实现runnable接口,重写run()方法,执行线程需要丢入runnable接口实现类,调用start开启线程
线程的状态
join:插队的用于VIP的设置,十分霸气他执行时其他的都要等着他
死锁:就是多个线程互相拥抱着对方需要的资源,然后形成的僵持
lock:锁 用法lock. lock();这就锁住了 解锁代码是lock.unlock();