zoukankan      html  css  js  c++  java
  • 多线程测试

    package actors;
    //多线程测试
    public class Actor extends Thread{
    public void run(){
    System.out.println(getName()+"演员");
    int count = 0;
    boolean keepRunning = true;
    while(keepRunning){
    System.out.println(getName()+"登台演出"+ (++count));
    if(count == 100){
    keepRunning = false;
    }
    if(count%10 == 0){
    try {
    Thread.sleep(3000);//1s
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    }
    System.out.println(getName()+"演出结束--------------over----wenhui");
    }

    public static void main(String[] args){
    Thread ac = new Actor();
    ac.setName("张三Thread");
    ac.start();
    Thread actress = new Thread(new Actress());
    actress.setName("李四Rnnable");
    actress.start();
    }
    }
    class Actress implements Runnable{
    public void run(){
    System.out.println(Thread.currentThread().getName()+"演员");
    int count = 0;
    boolean keepRunning = true;
    while(keepRunning){
    System.out.println(Thread.currentThread().getName()+"登台演出"+ (++count));
    if(count == 100){
    keepRunning = false;
    }
    if(count%10 == 0){
    try {
    Thread.sleep(1000);//1s
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    }
    System.out.println(Thread.currentThread().getName()+"演出结束--------------over----liujie");
    }

    }

  • 相关阅读:
    多项式乘法
    容斥计算多重组合
    D. Tokitsukaze, CSL and Stone Game
    优惠买商品(dp、greedy)
    数星星(单点更新,求前缀和)
    信息推送(单点更新,求前缀和)
    互相送礼物
    Codeforces Round #611 (Div. 3)E. New Year Parties
    多源bfs
    mysql事务和锁
  • 原文地址:https://www.cnblogs.com/j-liu3323/p/7651373.html
Copyright © 2011-2022 走看看