티스토리 뷰

java thread lambda사용법 iterate, thread

 

1
2
3
4
5
6
indicateDatetime.add(Calendar.HOUR, -1);
liveBaseGames.removeIf(liveBaseGame -> {
    //뒤에꺼가 앞에꺼보다 크면 -1
    Calendar startDatetime = getDate(liveBaseGame);
    return indicateDatetime.compareTo(startDatetime) == 1;
});
cs

자바 람다 필터

 

iterate는 이터레이트라고 읽는다 의미는 '반복할 수 있는'이다. each라고 생각하면 된다.

1
2
3
4
5
6
7
8
9
10
/**
 * Created by kyeongrok.kim on 2017-04-20.
 * 람다 연습
 */
public class PrLambda {
    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(123456);
        numbers.forEach((Integer value) -> System.out.println(value));
    }
}
cs

 

thread를 생성하려면 아래와 같이 여러줄이 필요한데 람다 표현식을 이용하면 한줄에 끝낼 수 있습니다.

new Thread(context.getBean("volleyballNormalAdapter", NormalRunnable.class)).start();
new Thread(() -> { new ImportantGameProcessor().process(); }).start();

 

 

람다식으로 타이머 실행

public class Lambda {
    public static void main(String[] args) {
        Timer t = new Timer(1000, event-> System.out.println("hello"));
        t.start();

        try{
            Thread.sleep(2000);
        }catch (InterruptedException e){

        }
    }
}
 

 

 

 

end.

 

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
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
31
글 보관함