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

上一篇:spark 读取mysql分区优化


下一篇:java多线程概念及实现方式