编程语言
首页 > 编程语言> > JAVA多线程

JAVA多线程

作者:互联网

进程

概念:

多线程


public class MyRunnable extends Thread{
	public void run() {
		for(int i=0;i<20;i++) {
			try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName()+" "+i);
		}
		
	}
}

public class Test {
                 public static void main(String[] args) {
					/*Main t1=new Main();
					Main t2=new Main();
					//t1.run();体现不出多线程
					t1.start();
					t2.start();
					*/
                	 MyRunnable r1=new MyRunnable();
                	 Thread t3=new Thread(r1);
                	
                	 MyRunnable r3=new MyRunnable();
                	 Thread t4=new Thread(r3);
                	 t3.start();
                	 t4.start();
				}
}

标签:MyRunnable,JAVA,Thread,int,多线程,public
来源: https://www.cnblogs.com/kingwz/p/15681785.html