1、线程的生命周期
2、模拟死锁
相关命令”
jps:查找运行程序pid
jstack pid:查看线程栈
package com.zw.rule.service.util;
public class DeadLock {
private static Object obj1 = new Object();
private static Object obj2 = new Object();
public static void main(String[] args) {
new Thread(new Thread1()).start();
new Thread(new Thread2()).start();
}
private static class Thread1 implements Runnable{
@Override
public void run() {
synchronized (obj1){
try {
System.out.println(">>>>>>>>>>>>>>>>"+Thread.currentThread().getName()+"获取了obj1锁");
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace