zoukankan      html  css  js  c++  java
  • 【线程控制:线程休眠】

    package com.test;
    
    import java.util.Date;
    
    public class ThreadSleep extends Thread {
    
        @Override
        public void run() {
            for (int x = 1; x < 10; x++) {
                System.out.println(getName() + ":" + x + ",日期:" + new Date());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    
    }
    package com.test;
    
    public class ThreadSleepTest {
    
        public static void main(String[] args){
    
            ThreadSleep ts1 = new ThreadSleep();
            ThreadSleep ts2 = new ThreadSleep();
            ThreadSleep ts3 = new ThreadSleep();
    
            ts1.setName("线程一");
            ts2.setName("线程二");
            ts3.setName("线程三");
    
            ts1.start();
            ts2.start();
            ts3.start();
    
        }
    
    }

     运行结果:

    线程一:1,日期:Mon Aug 27 23:06:00 CST 2018
    线程二:1,日期:Mon Aug 27 23:06:00 CST 2018
    线程三:1,日期:Mon Aug 27 23:06:00 CST 2018
    线程一:2,日期:Mon Aug 27 23:06:01 CST 2018
    线程二:2,日期:Mon Aug 27 23:06:01 CST 2018
    线程三:2,日期:Mon Aug 27 23:06:01 CST 2018
    线程一:3,日期:Mon Aug 27 23:06:02 CST 2018
    线程二:3,日期:Mon Aug 27 23:06:02 CST 2018
    线程三:3,日期:Mon Aug 27 23:06:02 CST 2018
    线程一:4,日期:Mon Aug 27 23:06:03 CST 2018
    线程二:4,日期:Mon Aug 27 23:06:03 CST 2018
    线程三:4,日期:Mon Aug 27 23:06:03 CST 2018
    线程一:5,日期:Mon Aug 27 23:06:04 CST 2018
    线程二:5,日期:Mon Aug 27 23:06:04 CST 2018
    线程三:5,日期:Mon Aug 27 23:06:04 CST 2018
    线程一:6,日期:Mon Aug 27 23:06:05 CST 2018
    线程二:6,日期:Mon Aug 27 23:06:05 CST 2018
    线程三:6,日期:Mon Aug 27 23:06:05 CST 2018
    线程一:7,日期:Mon Aug 27 23:06:06 CST 2018
    线程二:7,日期:Mon Aug 27 23:06:06 CST 2018
    线程三:7,日期:Mon Aug 27 23:06:06 CST 2018
    线程一:8,日期:Mon Aug 27 23:06:07 CST 2018
    线程二:8,日期:Mon Aug 27 23:06:07 CST 2018
    线程三:8,日期:Mon Aug 27 23:06:07 CST 2018
    线程一:9,日期:Mon Aug 27 23:06:08 CST 2018
    线程二:9,日期:Mon Aug 27 23:06:08 CST 2018
    线程三:9,日期:Mon Aug 27 23:06:08 CST 2018
    终身学习者
  • 相关阅读:
    【drp 11】使用Junit简单测试接口方法
    【Struts 1】Struts1的基本原理和简介
    【drp 10】JSP页面中model1和model2的区别
    【drp 9】Servlet生命周期
    【Nginx 3】FTP远程文件下载
    [drp 8]get和post的区别,以及乱码问题的解决
    svn update错误
    easyui只打开一个tab
    ubuntu安装skype
    单独使用CKfinder上传图片
  • 原文地址:https://www.cnblogs.com/zuixinxian/p/9545448.html
Copyright © 2011-2022 走看看