- class simpleThread1 implements Runnable
- {
- int k=10;
- public void run()
- {
- for (int i = 0; i < 10; i++)
- {
- if(k>0)
- System.out.println(Thread.currentThread().getName()+"::"+k--);
- }
- }
- }
- class simpleThread
- {
-
- public static void main(String[] args) throws Exception
- {
- Thread demo ;
- simpleThread1 he = new simpleThread1();
- demo = new Thread(he,"线程");
- // demo.start();
- //demo.join();
- for(int i=0;i<50;++i){
- if(i>10){ //关键在此处,为什么i==0判断没问题,用i>10判断就会报错呢
- try{
-
- // Thread demo = new Thread(he,"线程");
- demo.start();
- demo.join();
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
- System.out.println("main 线程执行-->"+i);
- }
- }
- }
复制代码 |
|