这个随便弄的好像也行。。。
- package cn.itcast.day;
- public class ThreadTest {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- My_Print mp = new My_Print();
- new Thread(mp,"1").start();
- new Thread(mp,"2").start();
- new Thread(mp,"3").start();
- }
- }
- class My_Print implements Runnable{
- private int num = 1;
- private int k = 1;
- public void print(){
- for(int x = 0; x < 5 ;x++)
- System.out.println(Thread.currentThread().getName()+ "::" + num++);
- }
- @Override
- public void run() {
- // TODO Auto-generated method stub
- while(num <= 75){
- if(k == 1&&Thread.currentThread().getName().equals("1")&& num <= 75){
- print();
- k = 2;
- }
- if(k == 2&&Thread.currentThread().getName().equals("2")&& num <= 75){
- print();
- k = 3;
- }
- if(k == 3&&Thread.currentThread().getName().equals("3")&& num <= 75){
- print();
- k = 1;
- }
- }
- }
-
- }
复制代码 |