zoukankan      html  css  js  c++  java
  • java多线程 实现Runnable 接口

    编写代码

    package com.xiang.lesson03;
    
    //创建线程方式2, 实现Runnable 接口,重写run 方法,
    public class TestThread1 implements  Runnable{
        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                System.out.println("循环---+"+i);
            }
        }
    //这是一个交替执行的过程
        public static void main(String[] args) {
    //        创建Runnable 接口 的实现类
            TestThread1 thread1 = new TestThread1();
            //        创建线程对象,通过线程对象来开启我们的线程,代理;
    //        Thread thread = new Thread(thread1);
    //        thread.start();
    
            new  Thread(thread1).start();
            for (int i = 0; i < 10; i++) {
                System.out.println("循环第"+i+"次");
            }
        }
    
    }
    
    

    运行结果

    循环第0次
    循环---+0
    循环第1次
    循环第2次
    循环第3次
    循环第4次
    循环第5次
    循环第6次
    循环第7次
    循环第8次
    循环第9次
    循环---+1
    循环---+2
    循环---+3
    循环---+4
    循环---+5
    循环---+6
    循环---+7
    循环---+8
    循环---+9
    
    Process finished with exit code 0
    
    
  • 相关阅读:
    mybatis(十)缓存
    mybatis(八)复杂查询
    mybatis(六)分页
    mybatis(九)动态SQL
    mybatis(七)只用注解开发
    mybatis(五) 日志
    log4j.properties 相关配置
    mybatis(四)中可能出现的问题
    MyBatis(三) 配置解析
    IIS 发布 .net core 3.1
  • 原文地址:https://www.cnblogs.com/d534/p/15239687.html
Copyright © 2011-2022 走看看