1 package ch.hslu.exercises.sw08.ex4;
2
3 import java.util.List;
4 import java.util.concurrent.Callable;
5
6
7
8
9
10 public final class Producer implements Callable<Long> {
11
12 private final List<Integer> list;
13 private final int maxRange;
14
15
16
17
18
19
20
21
22 public Producer(final List<Integer> list, final int max) {
23 this.list = list;
24 this.maxRange = max;
25 }
26
27
28
29
30
31
32
33 @Override
34 public Long call() throws Exception {
35 long sum = 0;
36 for (int i = 1; i <= maxRange; i++) {
37 sum += i;
38 list.add(i);
39 }
40 return sum;
41 }
42 }