代码更新
This commit is contained in:
Binary file not shown.
28
java/多线程与并发/synchronized 关键字/对象锁:实例1.txt
Normal file
28
java/多线程与并发/synchronized 关键字/对象锁:实例1.txt
Normal 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();
|
||||
}
|
||||
}
|
||||
27
java/多线程与并发/synchronized 关键字/方法锁:实例1.txt
Normal file
27
java/多线程与并发/synchronized 关键字/方法锁:实例1.txt
Normal 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();
|
||||
}
|
||||
}
|
||||
BIN
java/多线程与并发/多线程与并发.xmind
Normal file
BIN
java/多线程与并发/多线程与并发.xmind
Normal file
Binary file not shown.
Reference in New Issue
Block a user