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();
    
        }
    
    }

  • 相关阅读:
    驱动编程:内存管理基本函数
    POOL_TYPE enumeration
    远程服务器下载jenkins上生成的war包,失败原因
    jenkins ssh 报错
    git分组
    免密登录
    jenkins 生成war包后的下载
    redis 连接失败
    nginx+tomcat+https
    jenkins 拉取 git 代码成功版本
  • 原文地址:https://www.cnblogs.com/zhailiming/p/5558154.html
Copyright © 2011-2022 走看看