다 중 스 레 드 사용

더 읽 기

package cm.aichijihua;

public class ThreadTest1 {
	

	public static void main(String[] args) {
		
		
		//   1      run()           run   
		Thread thread = new Thread(){
			@Override
			public void run() {
				
				while (true) {
					
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						
						e.printStackTrace();
					}
					
					System.out.println(Thread.currentThread().getName());
					System.out.println(this.getName());
				}
				
			}
		};
		thread.start();
		
		
		//   2        ,           Runable   run            
		//                  ,       run    Runable   
		Thread thread2 = new Thread(new Runnable() {
			
			@Override
			public void run() {
				
				while (true) {
					
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						
						e.printStackTrace();
					}
					System.out.println(Thread.currentThread().getName());
				}
				
			}
		});
		thread2.start();
		
		
		//           ,           ,         ,    Runable  run  
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				while (true) {
					
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						
						e.printStackTrace();
					}
					System.out.println("     ");
				}
				
			}
		}){
			public void run() {
				while (true) {
					
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						
						e.printStackTrace();
					}
					System.out.println("     ");
				}
			};
		}.start();
		
	}
	
}


좋은 웹페이지 즐겨찾기