FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/concurrent/QuittingTasks.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
concurrent
/
QuittingTasks.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (34 loc) · 1.2 KB
Breadcrumbs
OnJava8-Examples
/
concurrent
/
QuittingTasks.java
Copy path
File metadata and controls
35 lines (34 loc) · 1.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
32
33
34
35
// concurrent/QuittingTasks.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import
java
.
util
.*;
import
java
.
util
.
stream
.*;
import
java
.
util
.
concurrent
.*;
import
onjava
.
Nap
;
public
class
QuittingTasks
{
public
static
final
int
COUNT
=
150
;
public
static
void
main
(
String
[]
args
) {
ExecutorService
es
=
Executors
.
newCachedThreadPool
();
List
<
QuittableTask
>
tasks
=
IntStream
.
range
(
1
,
COUNT
)
.
mapToObj
(
QuittableTask
::
new
)
.
peek
(
qt
->
es
.
execute
(
qt
))
.
collect
(
Collectors
.
toList
());
new
Nap
(
1
);
tasks
.
forEach
(
QuittableTask
::
quit
);
es
.
shutdown
();
}
}
/* Output:
11 23 20 12 24 16 19 15 35 147 32 27 7 4 28 31 8 83 3 1
13 9 5 2 6 18 14 17 21 25 22 26 29 30 33 34 37 41 38 46
45 49 50 53 57 58 54 69 104 112 40 73 74 115 116 70 119
77 81 56 85 78 82 111 86 90 48 89 36 108 107 44 55 52
43 60 63 59 64 71 68 67 75 76 72 79 80 84 87 88 66 91
10 95 65 96 94 92 62 100 61 93 47 39 51 99 103 128 123
127 124 140 120 139 136 135 143 148 144 105 102 131 101
132 98 97 149 137 134 42 106 110 109 114 133 113 117
118 130 129 126 121 125 122 138 141 145 142 146
*/
Back
|
FazBrowse Home
|
New Git URL