欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入
* 以验证当前线程对象的锁被占用时, 是否可以访问其他同步代码块
*/
//Thread.sleep(2000);
//this.wait(2000);//只能在同步代码块中调用wait方法
this.wait();
System.out.println(”Before: ” + number);
number *= 200;
System.out.println(”After: ” + number);
}
}
@Override
public void run() {
try {
firstMethod();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
ThreadTest threadTest = new ThreadTest(); 、
Thread thread = new Thread(threadTest);
System.out.println(Thread.currentThread());
//thread.run(); // 不会创建新线程,直接调用run方法
thread.start();// 开始执行该线程(创建一个新线程),由Java虚拟机调用该线程的run方法
//Thread.sleep(1000);
threadTest.secondMethod();
}
}
[1][2]
你能给的也只有这么多,在这个狭小的圈子里,