[Java] 83. Thread 동시 작업 처리 예제

백하림's avatar
Feb 21, 2025
[Java] 83. Thread  동시 작업 처리 예제
package ex19; class MyFile { public void write() { try { Thread.sleep(5000); System.out.println("파일 쓰기 완료"); } catch (InterruptedException e) { throw new RuntimeException(e); } } } class 화가 { public void 그림그리기() { System.out.println("그림 그리기 완료"); } } // 화가 public class Th03 { public static void main(String[] args) { // 이걸 잘 해야 좋은 UX MyFile myFile = new MyFile(); 화가 painter = new 화가(); painter.그림그리기(); new Thread(() -> { myFile.write(); }).start(); painter.그림그리기(); } }
“파일 쓰기 완료”는 5초 후 출력된다.
“파일 쓰기 완료”는 5초 후 출력된다.
Share article

harimmon