- package com.yaya.test;
- public class Test12 {
- public static void main(String[] args) {
- chushou c=new chushou();
- Thread t1=new Thread(c,"aa");
- Thread t2=new Thread(c,"bb");
- Thread t3=new Thread(c,"cc");
- t1.start();
- t2.start();
- t3.start();
- }
-
- }
- class chushou implements Runnable{
- private int num=100;
- private boolean panduan=true;
- @Override
- public void run() {
- while(panduan){
- test();
- }
-
- }
- public /*synchronized*/ void test(){
- if(num<=0){
- panduan=false;
- return;
- }
- System.out.println(Thread.currentThread().getName()+"***"+num--);
- }
-
- }
复制代码 |