Thread3 Thread / Runnable / Thread Pool Thread어떤 프로그램 내에서 실행되는 흐름의 단위특히 프로세스 내에서 실행되는 흐름의 단위 Runnable쓰레드의 run( ) 메서드만 가지고 있는 인터페이스다중 상속이 되지 않는 문제를 해결하기 위해 생긴 인터페이스사용시 Runnable객체를 생성후 해당 객체를 Thread로 생성하여 사용한다.Runnable runnable1 = new MyServer(); Runnable runnable2 = new MyServer(); Thread thread1 = new Thread(runnable1); Thread thread2 = new Thread(runnable2); thread1.start(); thread2.start();Thread Pool쓰레드를 미리 원하는 갯수 만큼 생성해 두는 것Execut.. Study/WAS만들기 2023. 6. 11. Thread / Runnable Thread쓰레드를 사용하려는 클래스에 Thread를 상속받아 사용한다.각 쓰레드는 각각의 Stack을 가지고 있다.각각의 Stack을 가지고 있기 때문에 개별로 로직처리가 가능해 동시에 작업이 가능하다.run( )쓰레드를 상속받으면 반드시 재정의해 주어야 하는 메서드쓰레드 작업을 할 로직을 작성해준다.public class MyThread extends Thread { @Override public void run(){ ... } } start( )Thread를 상속받은 클래스의 run( ) 메서드를 실행 시켜주는 메서드public class TestThread { MyThread myThread = new MyThread(); myThread.start(); }Runnable쓰레드를 상속받게 되면 다.. Study/WAS만들기 2023. 6. 11. 멀티캠퍼스 15일차 (완) 한줄 코드는 { } 생략이 가능하다. 01. Exception Exception 예외발생 ~ 처리 예외전과 예외만들기 System.out.println(e.getMessage()); 에러 발생 이유를 보여주는 print 메소드 e.printStackTrace(); 에러 발생 이유를 디테일하게 보여주는 메소드 (위치, 이유 등) System.out.println(e.getMessage()); 보다 많이 사용함‼️ 01-1. 예외발생 ~ 처리 📕Exception-1(클릭하여 예제보기) 📕Exception-2(클릭하여 예제보기) 📕Exception-3(클릭하여 예제보기) try-catch문 try에 오류가 발생할만한 문장 삽입 catch에 오류발생시 어떻게 처리할지 입력 ERROR가 많으면 catch를 추가해.. Language/Java 2022. 10. 31. 이전 1 다음 728x90 반응형