blob: 5efdcf33254db26ebbac4b95f90f68dc6356caa1 (
plain)
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
|
package com.orbekk.same;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class BroadcasterImpl implements Broadcaster {
private Executor executor;
/**
* Get a BroadcastRunner for ClientService using a thread pool of size 20.
*/
public static BroadcasterImpl getDefaultBroadcastRunner() {
return new BroadcasterImpl(Executors.newFixedThreadPool(20));
}
public BroadcasterImpl(Executor executor) {
this.executor = executor;
}
public synchronized void broadcast(final List<String> targets,
final ServiceOperation operation) {
for (final String t : targets) {
executor.execute(new Runnable() {
@Override public void run() {
operation.run(t);
}
});
}
}
}
|