zoukankan      html  css  js  c++  java
  • Java线程入门案例演示(一)

    /**
     * 
     * 线程演示
     */
    package cn.wang.test1;

    public class demo1 {

    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    dog dg1 = new dog();
    dog2 dg2 = new dog2();
    Thread t1 = new Thread(dg1);
    Thread t2 = new Thread(dg2);
    t1.start();
    t2.start();

    }

    }
    class dog implements Runnable{
    int n=0;
    public void run(){
    while(true){
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    n++;
    if(n==5) break;
    System.out.println("dog1线程");
    }
    }
    }

    class dog2 implements Runnable{
    int n=0;
    public void run(){
    while(true){
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    n++;
    if(n==5) break;
    System.out.println("dog2线程");
    }
    }
    }
  • 相关阅读:
    LOJ#551 Matrix
    洛谷P5163 WD与地图
    洛谷P4831 Scarlet loves WenHuaKe
    LOJ#6118 鬼牌
    支配树
    线性插值
    PropertiesConfiguration
    ThreadLocal
    Thread
    FastJson
  • 原文地址:https://www.cnblogs.com/toge/p/6114701.html
Copyright © 2011-2022 走看看