本帖最后由 在乎.. 于 2013-7-13 11:02 编辑
发博客时候出出现代码里面
- public class P03_11 implements Runnable {
- <span style="white-space:pre"> </span>static Object S1 = new Object(), S2 = new Object();
-
-
- <span style="white-space:pre"> </span>public void run() {
- <span style="white-space:pre"> </span>if (Thread.currentThread().getName().equals("th1")) {
- <span style="white-space:pre"> </span>synchronized (S1)
-
-
- <span style="white-space:pre"> </span>{
- <span style="white-space:pre"> </span>System.out.println("线程1锁定S1");
- <span style="white-space:pre"> </span>try {
- <span style="white-space:pre"> </span>Thread.sleep(1000);
- <span style="white-space:pre"> </span>} catch (Exception ex) {
- <span style="white-space:pre"> </span>}
|
|