?? thread_2.java
字號:
package thread2;
class TestThread {
public void execute(){ //synchronized,未修飾
for(int i=0;i<20;i++){
try {
Thread.sleep(100); //比thread1 包中多出來的一句話1!!!!!!!!!!!!!!!!!!!!
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+Thread.currentThread().getName()+" "+i);
}
}
}
class ThreadA implements Runnable{
TestThread test=null;
public ThreadA(TestThread pTest){ //對象有外部引入,這樣保證是同一個對象
test=pTest;
}
public void run() {
test.execute();
}
}
public class Thread_2{
public static void main(String[] args){
TestThread test=new TestThread();
Runnable runabble=new ThreadA(test);
Thread a=new Thread(runabble,"A");
a.start();
Thread b=new Thread(runabble,"B");
b.start();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -