java 一个线程执行加,一个线程执行减

来源:互联网 发布:mac怎么卸载插件 编辑:程序博客网 时间:2024/06/06 18:25
package com.base;/** *  * @author zzh * 一个线程执行加,一个线程执行减 */class MyThreadA implements Runnable{     private boolean flag=true;     public void run(){         int i=0;         while(this.flag){             while(true){                 System.out.println(Thread.currentThread().getName()+"运行,i="+(i++));             }         }     } }     class MyThreadB implements Runnable{         private boolean flag=true;         public void run(){             int i=0;             while(this.flag){                 while(true){                     System.out.println(Thread.currentThread().getName()+"运行,i="+(i--));                 }             }         }     }          public class Mythread {     public static void main(String[] args) {         MyThreadA A=new MyThreadA();         MyThreadB B=new MyThreadB();         Thread A1=new Thread(A,"线程");         Thread B1=new Thread(B,"xc");         A1.start();         B1.start();      }  }