thread12.java

来自「java关于线程的一些实例」· Java 代码 · 共 30 行

JAVA
30
字号
class Priter{
	synchronized void printChar(char ch){
		for(int i=1;i<=10;i++)
			System.out.print(ch);
	}
}
class PrinterThread extends Thread{
	Priter ptr;
	char ch;
	PrinterThread(Priter ptr,char ch){
		this.ptr=ptr;
		this.ch=ch;
	}
	public void run(){
		for(int i=1;i<=10;i++){
			ptr.printChar(ch);
			System.out.println();
		}
	}
}
public class Thread12 {
    public static void main(String[] args){
    	Priter ptr=new Priter();
    	PrinterThread pt1=new PrinterThread(ptr,'A');
    	PrinterThread pt2=new PrinterThread(ptr,'B');
    	pt1.start();
    	pt2.start();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?