3

I'm building my concurrent application on top of GPars library. It contains a thread pool under the hood, so I would like to solve all concurrency-related tasks by means of this pool.

I need to run a task with a certain delay (e.g. 30 seconds). Also I want to run some tasks periodically.

Are there any ways to implements these things with GPars?

Roman
  • 64,384
  • 92
  • 238
  • 332

1 Answers1

0

What about Thread.sleep for delaying and Quartz for scheduling? I know there are the obvious choices but I don't see anything wrong with using them.

What I mean is to mix GPars with a bit of higher order closures e.g.:

@Grab(group='org.codehaus.gpars', module='gpars', version='1.2.1')

def delayDecorator = {closure, delay ->
    return {params ->
        Thread.sleep (delay)
        closure.call (params)
    }
}

groovyx.gpars.GParsPool.withPool() {
    def closures = [{println it},{println it + 1}], delay = 1000
    closures.collect(delayDecorator.rcurry(delay)).eachParallel {it (1)}
}
defectus
  • 1,947
  • 2
  • 16
  • 21