zoukankan      html  css  js  c++  java
  • java,多线程实现

    package org.hanqi.thread;
    
    public class Test1 {
    
        public static void main(String[] args) {
            
    //        for(int i=0;i<10;i++)
    //        {
    //            System.out.println(i);
    //            
    //            try {
    //                //线程的休眠方法(毫秒)
    //            Thread.sleep(1000);
    //            } catch (InterruptedException e) {
    //                
    //                e.printStackTrace();
    //            }
    //        }
    
                TestThread1 tt1=new TestThread1();
                
                //启动多线程
                tt1.start();
                
                TestThread1 tt2=new TestThread1();
                tt2.start();
                
                //启动实现接口方式的多线程
                Thread t3=new Thread(new TestThread2());
                
                t3.start();
                
            
    
        }
    
    }
    View Code
    package org.hanqi.thread;
    //支持多线程
    //1.继承Thread
    //2.覆盖run方法
    
    public class TestThread1 extends Thread {
        //重写
        public void run()
        {
            for(int i=0;i<10;i++)
            {
                System.out.println(i);
                
                try {
                    //线程的休眠方法(毫秒)
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    
                    e.printStackTrace();
                }
            }
            
        }    
    
    }
    View Code
    package org.hanqi.thread;
    
    public class TestThread2 implements Runnable {
    
        @Override
        public void run() {
            
            for(int i=0;i<10;i++)
            {
                System.out.println(i);
                
                try {
                    //线程的休眠方法(毫秒)
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    
                    e.printStackTrace();
                }
            }
        }
    
    }
    View Code

  • 相关阅读:
    Pymsql
    MySQL基础操/下
    MySQL基础操作
    前端学习之jquery/下
    前端学习之jquery
    Python之异常处理
    Python之模块和包导入
    Python之模块
    Python之面向对象上下文管理协议
    Python之面向对象slots与迭代器协议
  • 原文地址:https://www.cnblogs.com/jiang2538406936/p/5279787.html
Copyright © 2011-2022 走看看