강의

멘토링

로드맵

Inflearn brand logo image

인프런 커뮤니티 질문&답변

임다정님의 프로필 이미지
임다정

작성한 질문수

스레드 생성과실행-2 강의에서

작성

·

29

0

문제와풀이 마지막문제인데요

 

package thread.test;

import static thread.util.MyLogger.log;

public class StartTest4Main {
    public static void main(String[] args) {

        Runnable runnable1 = new Runnable() {
            @Override
            public void run() {
                log("A");
            }
        };

        Runnable runnable2 = new Runnable() {
            @Override
            public void run() {
                log("B");
            }
        };

        for (; ; ) {
            Thread threadA = new Thread(runnable1);
            threadA.setName("Thread-A");
            threadA.start();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }


            Thread threadB = new Thread(runnable2);
            threadB.setName("Thread-B");
            threadB.start();
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }
}

저는 코드를 이렇게 구현했는데 틀린걸까요?

답변

답변을 기다리고 있는 질문이에요
첫번째 답변을 남겨보세요!
임다정님의 프로필 이미지
임다정

작성한 질문수

질문하기