티스토리 뷰

java 람다로 무한루프 스레드 돌리기

Runnable r2 = ()-> {while(true){ System.out.println("hello"); try{Thread.sleep(2*1000l);}catch(Exception e){} }};

r2.run();

end.


일반 Runnable

Runnable r1 = new Runnable() {

    @Override
public void run() {

}
};


람다 Runnable

Runnable r1 = ()->{

    };



hello를 한번 출력하는 thread 생성

new Thread(() -> { System.out.println("hello"); }).start();



2초마다 한번 hello를 무한 출력하는 thread생성

new Thread(() -> {
while(true){
System.out.println("hello");
try{Thread.sleep(2*1000l);}catch(Exception e){}
}
}).start();


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함