gpars

How know with GPars that all threads have finished when an exception is thrown?

橙三吉。 提交于 2019-12-24 13:07:57
问题 In the case of a thread throwing an exception, how can I wait until all threads that did not throw an exception have finished (so the user doesn't launch again until everything has stopped)? I use GPars in several different ways, so I need a strategy for each (parallel collections, async closures, and fork/join). The exceptions are not getting buried, they are nicely handled via promises, getChildrenResults, etc., so that's not an issue (thanks to Vaclav Pech's answers). I just need to make

GPars - proper way to terminate a parallel collection early

岁酱吖の 提交于 2019-12-11 15:25:51
问题 What is the best way to terminate a parallel collection (in the case of either an exception thrown by one of the threads, or an interrupt initiated by the user)? In either case, I could easily set some flag and just check it at the top of the loop. But if I've got 10,000 items in the collection, I'd rather tell whatever feeds those into the ForkJoinPool to stop feeding them in. Let the 5 or 20 or so that already started finish, but don't start any more. Here's a sample you could plug in to

GPars report status on large number of async functions and wait for completion

♀尐吖头ヾ 提交于 2019-12-11 03:06:41
问题 I have a parser, and after gathering the data for a row, I want to fire an aync function and let it process the row, while the main thread continues on and gets the next row. I've seen this post: How do I execute two tasks simultaneously and wait for the results in Groovy? but I'm not sure it is the best solution for my situation. What I want to do is, after all the rows are read, wait for all the async functions to finish before I go on. One concern with using a collection of Promises is

Grails, GPars and data persistence

让人想犯罪 __ 提交于 2019-12-06 21:44:29
问题 Something is not getting flushed. A simplified example of what's happening: def testDemo() { def person = new Person(...) person.save(flush: true) println "Number of people after save: " + Person.all.size() def dummyList = [1, 2, 3, 4, 5] GParsPool.withPool { num -> println "Number of people after withPool: " + Person.all.size() dummyList.eachParallel { println "Number of people after eachParallel " + Person.all.size() Person.withTransaction { ... This outputs: Number of people after save: 1

Handling database-backed async callbacks in Grails

懵懂的女人 提交于 2019-12-06 13:23:32
问题 I've been working on implementing an automated trading system in Grails based on Interactive Brokers' API (brief overview here: Grails - asynchronous communication with 3rd party API) for longer than I care to admit. This is a high-frequency trading strategy, so it's not as simple as placing an order for 100 shares and getting filled. There's a lot of R&D involved, so my architecture and design have been and continue to morph and evolve over time. What has become clear over the past month or

GPars: return of eachParallel{}

旧城冷巷雨未停 提交于 2019-12-06 01:54:06
问题 I want to do alot of stuff with each of those example strings and return Object of some other type here Integers, later some bigger class-objects. Here in this example I am trying something simple, how ever I get a completly wrong result. At least for what i was hoping to get back. xD I hoped to get: [6, 5, 6, 5] but instead I get: [butter, bread, dragon, table] package test @Grab(group='org.codehaus.gpars', module='gpars', version='1.0.0') import static groovyx.gpars.GParsPool.withPool class

Groovy (GPars) and MissingMethodException when calling eachParallel()

风流意气都作罢 提交于 2019-12-06 01:28:39
问题 When I run the following code in the console (groovy 2.1.3): strings = [ "butter", "bread", "dragon", "table" ] strings.eachParallel{println "$it0"} I get: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.eachParallel() is applicable for argument types: (ConsoleScript40$_run_closure1) values: [ConsoleScript40$_run_closure1@a826f5] Anyone can tell me what I am doing wrong? 回答1: I think you are missing the set up. Try @Grab(group='org.codehaus.gpars', module=

Grails, GPars and data persistence

℡╲_俬逩灬. 提交于 2019-12-05 01:23:45
Something is not getting flushed. A simplified example of what's happening: def testDemo() { def person = new Person(...) person.save(flush: true) println "Number of people after save: " + Person.all.size() def dummyList = [1, 2, 3, 4, 5] GParsPool.withPool { num -> println "Number of people after withPool: " + Person.all.size() dummyList.eachParallel { println "Number of people after eachParallel " + Person.all.size() Person.withTransaction { ... This outputs: Number of people after save: 1 Number of people after withPool: 1 Number of people after eachParallel: 0 I don't understand if I have

GPars: return of eachParallel{}

为君一笑 提交于 2019-12-04 06:51:51
I want to do alot of stuff with each of those example strings and return Object of some other type here Integers, later some bigger class-objects. Here in this example I am trying something simple, how ever I get a completly wrong result. At least for what i was hoping to get back. xD I hoped to get: [6, 5, 6, 5] but instead I get: [butter, bread, dragon, table] package test @Grab(group='org.codehaus.gpars', module='gpars', version='1.0.0') import static groovyx.gpars.GParsPool.withPool class Test { List<String> strings = new ArrayList<String>([ "butter", "bread", "dragon", "table" ]) def

Groovy (GPars) and MissingMethodException when calling eachParallel()

馋奶兔 提交于 2019-12-04 05:10:14
When I run the following code in the console (groovy 2.1.3): strings = [ "butter", "bread", "dragon", "table" ] strings.eachParallel{println "$it0"} I get: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.eachParallel() is applicable for argument types: (ConsoleScript40$_run_closure1) values: [ConsoleScript40$_run_closure1@a826f5] Anyone can tell me what I am doing wrong? Michael Rutherfurd I think you are missing the set up. Try @Grab(group='org.codehaus.gpars', module='gpars', version='1.0.0') import groovyx.gpars.GParsPool GParsPool.withPool { def strings = [