打印数字:
package com.sa.thread.练习.练习1;
import javax.swing.plaf.synth.SynthViewportUI;
/**
* Created by 123 on 2018-07-26
*/
public class PrintNum extends Thread{
public static boolean flag=true;
private int start;
private int end;
private String threaName;
public PrintNum() {
}
public PrintNum(int start, int end,String threaName) {
this.start = start;
this.end = end;
this.threaName=threaName;
}
@Override
public void run() {
for(int i=0;start<=end;i++){
m1(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public synchronized void m1(int i){
System.out.println("m1--NO------------------"+i+"次");
if(flag==true) {
for (int j = 0; j < 2; j++) {
System.out.println("开始打印数字:"+start);
start++;
}
flag = false;
}
}
}
打印字符:
package com.sa.thread.练习.练习1;
import static com.sa.thread.练习.练习1.PrintNum.flag;
/**
* Created by 123 on 2018-07-26
*/
public class PrintChar extends Thread{
private int start;
private int end;
private String threaName;
public PrintChar(char start,char end) {
}
public PrintChar(int start, int end,String threaName) {
this.start = s