Libraryless. Click here for Pure Java version (2914L/19K).
1 | static <A extends Runnable> void parallelDo(Cl<A> l, O... _) {
|
2 | parallelDo(iterator(l), l(l), _); |
3 | } |
4 | |
5 | static <A extends Runnable> void parallelDo(Iterator<A> it, int count, O... _) ctex {
|
6 | optPar int queueSize = 500; |
7 | optPar int poolSize = coresToUse_fixed(); |
8 | NotifyingBlockingThreadPoolExecutor e = new(poolSize, queueSize, 15, TimeUnit.SECONDS); |
9 | |
10 | // TODO: if poolSize == 1, do it in this thread |
11 | |
12 | new Var<Throwable> error; |
13 | try {
|
14 | for (A o : iterable(it)) {
|
15 | if (o == null) continue; |
16 | e.execute(r { pcall {
|
17 | try {
|
18 | o.run(); |
19 | } catch e {
|
20 | error.set(e); |
21 | } |
22 | }}); |
23 | } |
24 | e.shutdown(); |
25 | e.awaitTermination(1, TimeUnit.DAYS); |
26 | } finally {
|
27 | e.shutdown(); |
28 | } |
29 | |
30 | if (error.has()) |
31 | throw rethrow(error!); |
32 | } |
Began life as a copy of #1015446
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1029432 |
| Snippet name: | parallelDo |
| Eternal ID of this version: | #1029432/5 |
| Text MD5: | fb8e67bbf3eb8d80d7796b29d3c69ff7 |
| Transpilation MD5: | 4d33132c67683b3594d41619cbf19dab |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-08-06 18:45:46 |
| Source code size: | 809 bytes / 32 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 473 / 605 |
| Version history: | 4 change(s) |
| Referenced in: | [show references] |