0
private List<Thread> pupils = new ArrayList<>();
public (int groupNo, Position pos)
{
this.groupNo = groupNo;
this.position = pos;
for (int i = 1; i < 10; i++) {
pupils.add(new Thread(new Pupil(i, groupNo, pos)));
}
}
@Override
public void run()
{
pupils.forEach(t -> t.start());
// Here I would like to use Java 8 features instead of Iterator to loop through list
// of threads and start a thread at once. Only when one is complete start the next
// in order.
}
나는 차례로 시작하고자하는 Threads
리스트를 가지고 있습니다. 작업이 끝나면 다음 작업은 원하는 바톤 작업을 수행하고 작업을 수행합니다. 어떻게 순서대로 목록을 반복하고 join()
호출의 결과로 InterruptedException
을 처리하는 자바 람다 본체로 스레드를 시작할 수 있습니까?스레드를 시작하고 람다를 사용하여 join을 호출합니다.
두 번째 줄은 함수 선언으로 보이지만 이름이 없습니다. –