先看代码!
- class Demo implements Runnable
- {
- public synchronized void run()
- {
- try
- {
- wait();
- }
- catch (InterruptedException e)
- {
- }
- for (int x = 0;x<100 ;x++ )
- {
- System.out.println(Thread.currentThread().getName()+"..."+x);
- }
- }
- }
- class Demo4
- {
- public static void main(String[] args) throws Exception
- {
- Demo d = new Demo();
- Thread t1 = new Thread(d);
- t1.join();
- t1.start();
- for (int x = 0;x<100;x++ )
- {
- System.out.println("main..."+x);
- }
- System.out.println("Over!");
- }
- }
复制代码
在看老师视频时候,老师说join方法是用再start()前面,该线程执行完才执行其他线程,可是我让t1线程进去后wait那了, 为什么还能执行main呢 |