Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The GPars framework offers Java developers intuitive and safe ways to handle Java or Groovy tasks concurrently. Leveraging the enormous flexibility of the Groovy programing language and building on proven Java technologies, we aim to make concurrent programming for multi-core hardware intuitive, robust and enjoyable.

Code Block
withPool {

...


...

 

...

 

...

 

...

 def selfPortraits = images
        .findAllParallel{it.contains me}
        .collectParallel {it.resize()}
}

GPars is a multi-paradigm concurrency framework, offering several mutually cooperating high-level concurrency abstractions, such as Dataflow operators, Promises, CSP, Actors, Asynchronous Functions, Agents and Parallel Collections.

...

For the common scenario that one or multiple results are calculated concurrently but need to be processed as soon as they are available, GPars makes it a breeze to correctly model this with Dataflow. Dataflow variables and channels gives you a handy abstraction of single-assignment multiple-read data elements, while dataflow operators let you build efficient concurrent data-processing networks.

Code Block
final SyncDataflowQueue channel = new SyncDataflowQueue()

...



def producer = task {

...


...

    (1..30).each {

...


...

 

...

 

...

      channel << 

...

it  //writing to a channel

...


...

 

...

 

...

      println "Just sent $it"

...


...

    }

...


}

...



def consumer = task {

...


...

    while (true) {

...


...

 

...

 

...

      sleep 

...

500  //simulating a slow consumer

...


...

 

...

 

...

      final Object msg = channel.val

...


...

 

...

 

...

      println "Received $msg"

...


...

    }

...


}

...



producer.join()

The concept of Actors as an approach to organizing concurrent activities has recently gained new popularity (thanks to the Scala, Erlang, and other programming languages). GPars implements this concept for Java and Groovy developers. With actors support you can quickly create several independent Actors, which consume messages passed to them and communicate with other actors by sending them messages. You then build your solution by combining these actors into a communication network.

...