zoukankan      html  css  js  c++  java
  • java 线程测试 旅游 小练习

    package com.hanqi.xc;
    
    import java.util.Random;
    
    public class lvyou extends Thread {
    
        @Override
        public void run() {
            
            
            for(int i=0;i<10;i++)
            {
                
                System.out.println("Thread测试"+" "+Thread.currentThread().getName()  );
            
            try {
                
                Random r1 = new Random();
                
                int a = r1.nextInt(1000);
                
                Thread.sleep(a);
                
            } 
            catch (InterruptedException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
            }
            
        }
        
        
    
    }
    package com.hanqi.xc;
    
    public class cs {
    
        public static void main(String[] args) {
            
            
            lvyou l1 = new lvyou();
            
            l1.setName("拉萨");
            l1.start();
            
    
            lvyou l2 = new lvyou();
            
            l2.setName("大理");
            l2.start();
            
            
            
            
    //        Thread th = new Thread (new lvyou(),"青海");
    //        th.start();
    //        Thread th2 = new Thread (new lvyou(),"西藏");
    //        th2.start();
    
        }
    
    }

    package com.hanqi.xc;
    
    import java.util.Random;
    
    public class lvyou2 implements Runnable {
    
        @Override
        public void run() {
            
            for(int i=0;i<10;i++)
            {
                
                System.out.println("Runnable测试"+" "+Thread.currentThread().getName()  );
            
            try {
                
                Random r1 = new Random();
                
                int a = r1.nextInt(1000);
                
                Thread.sleep(a);
                
            } 
            catch (InterruptedException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
            }
            
    
        }
    
    }
    package com.hanqi.xc;
    
    public class cs {
    
        public static void main(String[] args) {
            
            
    //        lvyou l1 = new lvyou();
    //        
    //        l1.setName("拉萨");
    //        l1.start();
    //        
    //
    //        lvyou l2 = new lvyou();
    //        
    //        l2.setName("大理");
    //        l2.start();
    //        
            
            
            
            Thread th = new Thread (new lvyou2(),"青海");
            th.start();
            Thread th2 = new Thread (new lvyou2(),"西藏");
            th2.start();
    
        }
    
    }

  • 相关阅读:
    附加作业
    我的个人总结
    进度更新
    结对编程——电梯调度
    程序阅读的改进
    WordCount
    阅读程序
    VS2013单元测试
    附加作业
    个人最终总结
  • 原文地址:https://www.cnblogs.com/zhailiming/p/5558154.html
Copyright © 2011-2022 走看看