- public class TestThread{
- public static void main(String args[]){
- Thread1 t1=new Thread1();
- Thread2 t2=new Thread2();
- t1.start();
- t2.start();
- try{
- <FONT color=red>t1.join();
- </FONT>}catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- class Thread1 extends Thread{
- private int j=0;
- public void run(){
- for(int i=0;i<10;i++){
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("thread1:"+j++);
- }
- }
- }
- class Thread2 extends Thread{
- private int j=0;
- public void run(){
- for(int i=0;i<10;i++){
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("thread2:"+j++);
- }
- }
- }
复制代码 启动线程1和线程2之后,我的线程1使用了join()方法,为什么线程1还是和线程2轮流执行呢?不应该是线程1执行完了再执行线程2吗?求解释。。 |