You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: grails-doc/src/guide/7. Dataflow Concurrency.gdoc
+5-2
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,6 @@ final def z = new DataFlowVariable()
12
12
13
13
task {
14
14
z << x.val + y.val
15
-
println "Result: ${z.val}"
16
15
}
17
16
18
17
task {
@@ -22,6 +21,8 @@ task {
22
21
task {
23
22
y << 5
24
23
}
24
+
25
+
println "Result: ${z.val}"
25
26
{code}
26
27
27
28
Or the same algorithm rewritten using the _DataFlows_ class.
@@ -34,7 +35,6 @@ final def df = new DataFlows()
34
35
35
36
task {
36
37
df.z = df.x + df.y
37
-
println "Result: ${df.z}"
38
38
}
39
39
40
40
task {
@@ -44,6 +44,9 @@ task {
44
44
task {
45
45
df.y = 5
46
46
}
47
+
48
+
println "Result: ${df.z}"
49
+
47
50
{code}
48
51
49
52
We start three logical tasks, which can run in parallel and perform their particular activities. The tasks need to exchange data and they do so using *Dataflow Variables*.
Copy file name to clipboardexpand all lines: grails-doc/src/guide/7.1 Tasks.gdoc
+7-6
Original file line number
Diff line number
Diff line change
@@ -47,8 +47,7 @@ task {
47
47
it.val.toUpperCase().contains 'GROOVY'
48
48
}).size()
49
49
}
50
-
System.exit 0
51
-
}
50
+
}.join()
52
51
{code}
53
52
54
53
h3. Grouping tasks
@@ -73,7 +72,7 @@ group.with {
73
72
{code}
74
73
75
74
{note:Title=Custom thread pools for dataflow}
76
-
The default thread pool for dataflow tasks contains non-daemon threads, which means your application will not exit before all tasks complete.
75
+
The default thread pool for dataflow tasks contains daemon threads, which means your application will exit as soon as the main thread finishes and won't wait for all tasks to complete.
77
76
When grouping tasks, make sure that your custom thread pools either use daemon threads, too, which can be achieved by
78
77
using DefaultPGroup or by providing your own thread factory to a thread pool constructor,
79
78
or in case your thread pools use non-daemon threads, such as when using the NonDaemonPGroup group class, make sure you shutdown the group or the thread pool explicitly by calling its shutdown() method,
@@ -104,8 +103,7 @@ task {
104
103
it.val.toUpperCase().contains 'GROOVY'
105
104
}).size()
106
105
}
107
-
System.exit 0
108
-
}
106
+
}.join()
109
107
110
108
def downloadPage(def url) {
111
109
def page = new DataFlowVariable()
@@ -138,7 +136,7 @@ final def decelerationForce = new DataFlowVariable()
138
136
final def deceleration = new DataFlowVariable()
139
137
final def distance = new DataFlowVariable()
140
138
141
-
task {
139
+
def t = task {
142
140
println """
143
141
Calculating distance required to stop a moving ball.
{code}Note: I did my best to make all the physical calculations right. Feel free to change the values and see how long distance you need to stop the rolling ball.
Copy file name to clipboardexpand all lines: grails-doc/src/guide/7.3 Operators.gdoc
+1-1
Original file line number
Diff line number
Diff line change
@@ -235,7 +235,7 @@ group.with {
235
235
{code}
236
236
237
237
{note:Title=Custom thread pools for dataflow}
238
-
The default thread pool for dataflow operators contains non-daemon threads, which means your application will not exit before all operators are stopped.
238
+
The default thread pool for dataflow operators contains daemon threads, which means your application will exit as soon as the main thread finishes and won't wait for all tasks to complete.
239
239
When grouping operators, make sure that your custom thread pools either use daemon threads, too, which can be achieved by
240
240
using DefaultPGroup or by providing your own thread factory to a thread pool constructor,
241
241
or in case your thread pools use non-daemon threads, such as when using the NonDaemonPGroup group class, make sure you shutdown the group or the thread pool explicitly by calling its shutdown() method,
0 commit comments