zoukankan      html  css  js  c++  java
  • java 线程的使用

    java 线程的使用

    //线程的使用
    //需要记三个单词
    //1、Thread        线程的类名
    //2、 Runnable    线程的接口
    //3、 start        执行线程
    
    //使用继承线程类的方式实现线程
    class xc1 extends Thread{
        public void run(){
            for(int i=0;i<20;i++){
                System.out.println("次(继承类)线程的内容"+i);
            }
        }
    }
    
    //使用实现接口的方式实现线程(推荐使用)
    class xc2 implements Runnable{
        public void run(){
            for(int i=0;i<20;i++){
                System.out.println("次(接口实现)线程的内容"+i);
            }
        }
    }
    
    
    
    
    public class Index{
        public static void main(String[] args){
            
            //执行继承类的线程
            xc1    xc1    =    new xc1();
                xc1.start();
                
            //执行接口的线程
            xc2        xc2            =    new    xc2();
            Thread    xc2_Thread    =    new    Thread(xc2);
                    xc2_Thread.start();
            
            
            for(int i=20;i<40;i++){
                System.out.println("主线程的内容"+i);
            }
            
        }
    }

    .

  • 相关阅读:
    shell脚本-awk
    shell脚本-sed命令
    shell脚本-grep和正则表达式
    wuti
    dmesg、stat命令
    uname、hostname命令
    tee、vi/vim命令
    tr、od命令
    vimdiff、rev命令
    dos2unix、diff命令
  • 原文地址:https://www.cnblogs.com/phpyangbo/p/5964289.html
Copyright © 2011-2022 走看看