Java多线程例子

时间:2022-07-13 18:36:28
package rom;

import java.awt.image.AreaAveragingScaleFilter;

public class Xamle_2 {
	
	private  static Thread thread;
	private static Thread thread2;
	public static void main (String [] args)  {
		String [] a = {"aaa","bbb","ccc","ddd","eee"};
		String [] a1 = {"a1","a2","a3","a4","a5"};
		thread  = new Thread(new Runnable() {	
			@Override
			public void run() {
				for(int i=0;i<a1.length;i++) {
					System.out.println(a1[i]);
					try {
					Thread.sleep(1000);
					}catch(Exception e) {
						e.printStackTrace();
						
					}
				}	
			}
		});
		thread2 = new Thread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				for (int i = 0; i < a.length; i++) {
					System.out.println(a[i]);
					try {
						Thread.sleep(1000);
						}catch(Exception e) {
							e.printStackTrace();
						}
				}
				
			}
		});
		
		thread.start();
		thread2.start();

	}
}