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(); } }