代码更新

This commit is contained in:
2022-08-19 13:41:18 +08:00
parent ff906c1c20
commit 26c90f894c
4 changed files with 55 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,28 @@
class A implements Runnable {
static A a = new A(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@Override
public void run() {
// this<69><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󣨶<EFBFBD><F3A3A8B6><EFBFBD><EFBFBD>̱߳<DFB3><CCB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
synchronized (this) {
System.out.println("<22><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>" + Thread.currentThread().getName());
try {
Thread.sleep(3000);
} catch (Exception e) {
}
System.out.println(Thread.currentThread().getName() + "<22><><EFBFBD><EFBFBD>");
}
}
}
class B {
public static void main(String[] args) {
Thread thread1 = new Thread(A.a);
Thread thread2 = new Thread(A.a);
Thread thread3 = new Thread(A.a);
thread1.start();
thread2.start();
thread3.start();
}
}

View File

@@ -0,0 +1,27 @@
class A implements Runnable {
static A a = new A(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@Override
public void run() {
this.method();
}
public synchronized void method() {
System.out.println("<22><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>" + Thread.currentThread().getName());
try {
Thread.sleep(3000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + "<22><><EFBFBD><EFBFBD>");
}
}
class B {
public static void main(String[] args) {
Thread thread1 = new Thread(A.a);
Thread thread2 = new Thread(A.a);
thread1.start();
thread2.start();
}
}

Binary file not shown.