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
_Actors_ can be organized into groups and as a default there's always an application-wide pooled actor group available. And just like the _Actors_ abstract factory can be used to create actors in the default group, custom groups can be used as abstract factories to create new actors instances belonging to these groups.
The actors belonging to the same group share the *underlying thread pool* of that group. The pool by default contains *n + 1 threads*, where *n* stands for the number of *CPUs* detected by the JVM. The *pool size* can be set *explicitly* either by setting the _gpars.poolsize_ system property or individually for each actor group by specifying the appropriate constructor parameter.
266
266
267
267
{code}
268
-
def myGroup = new PooledActorGroup(10) //the pool will contain 10 threads
268
+
def myGroup = new DefaultPGroup(10) //the pool will contain 10 threads
269
269
{code}
270
270
271
-
The thread pool can be manipulated through the appropriate _PooledActorGroup_ class, which *delegates* to the _Pool_ interface of the thread pool. For example, the _resize()_ method allows you to change the pool size any time and the _resetDefaultSize()_ sets it back to the default value. The _shutdown()_ method can be called when you need to safely finish all tasks, destroy the pool and stop all the threads in order to exit JVM in an organized manner.
271
+
The thread pool can be manipulated through the appropriate _DefaultPGroup_ class, which *delegates* to the _Pool_ interface of the thread pool. For example, the _resize()_ method allows you to change the pool size any time and the _resetDefaultSize()_ sets it back to the default value. The _shutdown()_ method can be called when you need to safely finish all tasks, destroy the pool and stop all the threads in order to exit JVM in an organized manner.
272
272
273
273
{code}
274
274
... (n+1 threads in the default pool after startup)
275
275
276
-
Actors.defaultPooledActorGroup.resize 1 //use one-thread pool
276
+
Actors.defaultActorPGroup.resize 1 //use one-thread pool
277
277
278
278
... (1 thread in the pool)
279
279
280
-
Actors.defaultPooledActorGroup.resetDefaultSize()
280
+
Actors.defaultActorPGroup.resetDefaultSize()
281
281
282
282
... (n+1 threads in the pool)
283
283
284
-
Actors.defaultPooledActorGroup.shutdown()
284
+
Actors.defaultActorPGroup.shutdown()
285
285
{code}
286
286
287
-
As an alternative to the _PooledActorGroup_, which creates a pool of daemon threads, the _NonDaemonActorGroup_ class can be used when non-daemon threads are required.
287
+
As an alternative to the _DefaultPGroup_, which creates a pool of daemon threads, the _NonDaemonPGroup_ class can be used when non-daemon threads are required.
288
288
289
289
{code}
290
-
def daemonGroup = new PooledActorGroup()
290
+
def daemonGroup = new DefaultPGroup()
291
291
292
292
def actor1 = daemonGroup.actor {
293
293
...
294
294
}
295
295
296
-
def nonDaemonGroup = new NonDaemonActorGroup()
296
+
def nonDaemonGroup = new NonDaemonPGroup()
297
297
298
298
def actor2 = nonDaemonGroup.actor {
299
299
...
@@ -311,8 +311,8 @@ class MyActor {
311
311
Actors belonging to the same group share the *underlying thread pool*. With pooled actor groups you can split your actors to leverage multiple thread pools of different sizes and so assign resources to different components of your system and tune their performance.
312
312
313
313
{code}
314
-
def coreActors = new NonDaemonActorGroup(5) //5 non-daemon threads pool
315
-
def helperActors = new PooledActorGroup(1) //1 daemon thread pool
314
+
def coreActors = new NonDaemonPGroup(5) //5 non-daemon threads pool
315
+
def helperActors = new DefaultPGroup(1) //1 daemon thread pool
316
316
317
317
def priceCalculator = coreActors.actor {
318
318
...
@@ -342,15 +342,15 @@ Do not forget to shutdown custom pooled actor groups, once you no longer need th
342
342
h3. Common trap: App terminates while actors do not receive messages
343
343
344
344
Most likely you're using daemon threads and pools, which is the default setting, and your main thread finishes. Calling _actor.join()_ on any, some or all of your actors would block the main thread until the actor terminates and thus keep all your actors running.
345
-
Alternatively use instances of _NonDaemonActorGroup_ and assign some of your actors to these groups.
345
+
Alternatively use instances of _NonDaemonPGroup_ and assign some of your actors to these groups.
Copy file name to clipboardexpand all lines: grails-doc/src/guide/5.2 Special Actors.gdoc
+3-3
Original file line number
Diff line number
Diff line change
@@ -80,12 +80,12 @@ final def actor = new MyActor({
80
80
81
81
h3. Reactive Actor
82
82
83
-
The _ReactiveActor_ class, constructed typically by calling _Actors.reactor()_ or _PooledActorGroup.reactor()_, allow for more event-driven like approach. When a reactive actor receives a message, the supplied block of code, which makes up the reactive actor's body, is run with the message as a parameter. The result returned from the code is sent in reply.
83
+
The _ReactiveActor_ class, constructed typically by calling _Actors.reactor()_ or _DefaultPGroup.reactor()_, allow for more event-driven like approach. When a reactive actor receives a message, the supplied block of code, which makes up the reactive actor's body, is run with the message as a parameter. The result returned from the code is sent in reply.
Copy file name to clipboardexpand all lines: grails-doc/src/guide/6. Safe.gdoc
+3-3
Original file line number
Diff line number
Diff line change
@@ -140,14 +140,14 @@ To create a Safe instance belonging to a group, call the _safe()_ factory method
140
140
and tune performance of agents.
141
141
142
142
{code}
143
-
final def group = new NonDaemonActorGroup(5) //create a group around a thread pool
143
+
final def group = new NonDaemonPGroup(5) //create a group around a thread pool
144
144
def jugMembers = group.safe(['Me']) //add Me
145
145
{code}
146
146
147
147
{note:Title=Custom thread pools for agents}
148
148
The default thread pool for agents contains daemon threads. Make sure that your custom thread pools either use daemon threads, too, which can be achieved
149
-
either by using PooledActorGroup or by providing your own thread factory to a thread pool constructor,
150
-
or in case your thread pools use non-daemon threads, such as when using the NonDaemonActorGroup group class, make sure you shutdown the group or the thread pool explicitly by calling its shutdown() method,
149
+
either by using DefaultPGroup or by providing your own thread factory to a thread pool constructor,
150
+
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,
Copy file name to clipboardexpand all lines: grails-doc/src/guide/7.1 Dataflow tasks.gdoc
+4-4
Original file line number
Diff line number
Diff line change
@@ -56,9 +56,9 @@ Dataflow tasks can be organized into groups to allow for performance fine-tuning
56
56
to create tasks attached to the groups.
57
57
58
58
{code}
59
-
import groovyx.gpars.actor.PooledActorGroup
59
+
import groovyx.gpars.actor.DefaultPGroup
60
60
61
-
def group = new PooledActorGroup()
61
+
def group = new DefaultPGroup()
62
62
63
63
group.with {
64
64
task {
@@ -74,8 +74,8 @@ group.with {
74
74
{note:Title=Custom thread pools for dataflow}
75
75
The default thread pool for dataflow tasks contains non-daemon threads, which means your application will not exit before all tasks complete.
76
76
When grouping tasks, make sure that your custom thread pools either use daemon threads, too, which can be achieved by
77
-
using PooledActorGroup or by providing your own thread factory to a thread pool constructor,
78
-
or in case your thread pools use non-daemon threads, such as when using the NonDaemonActorGroup group class, make sure you shutdown the group or the thread pool explicitly by calling its shutdown() method,
77
+
using DefaultPGroup or by providing your own thread factory to a thread pool constructor,
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,
Copy file name to clipboardexpand all lines: grails-doc/src/guide/7.2 Dataflow operators.gdoc
+4-4
Original file line number
Diff line number
Diff line change
@@ -86,9 +86,9 @@ Dataflow operators can be organized into groups to allow for performance fine-tu
86
86
to create tasks attached to the groups.
87
87
88
88
{code}
89
-
import groovyx.gpars.actor.PooledActorGroup
89
+
import groovyx.gpars.actor.DefaultPGroup
90
90
91
-
def group = new PooledActorGroup()
91
+
def group = new DefaultPGroup()
92
92
93
93
group.with {
94
94
operator(inputs: [a, b, c], outputs: [d]) {x, y, z ->
@@ -101,7 +101,7 @@ group.with {
101
101
{note:Title=Custom thread pools for dataflow}
102
102
The default thread pool for dataflow operators contains non-daemon threads, which means your application will not exit before all operators are stopped.
103
103
When grouping operators, make sure that your custom thread pools either use daemon threads, too, which can be achieved by
104
-
using PooledActorGroup or by providing your own thread factory to a thread pool constructor,
105
-
or in case your thread pools use non-daemon threads, such as when using the NonDaemonActorGroup group class, make sure you shutdown the group or the thread pool explicitly by calling its shutdown() method,
104
+
using DefaultPGroup or by providing your own thread factory to a thread pool constructor,
105
+
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,
Copy file name to clipboardexpand all lines: grails-doc/src/guide/7.3 Dataflow implementation.gdoc
+1-1
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
The Dataflow Concurrency in GPars builds on top of its actor support. All of the dataflow tasks share a thread pool and so the number threads created through _DataFlow.task()_ factory method don't need to correspond to the number of physical threads required from the system.
2
-
The _DataFlow.task()_ factory method takes an optional actorGroup parameter to specify a group to which the task should belong. Since each group defines its own thread pool, you can easily organize tasks around different thread pools just like you do with actors.
2
+
The _PGroup.task()_ factory method can be used to attach the created task to a group. Since each group defines its own thread pool, you can easily organize tasks around different thread pools just like you do with actors.
0 commit comments