2.5 Applicability of Concepts - Reference Documentation
Authors: The Whole GPars Gang
Version: 1.0-SNAPSHOT
2.5 Applicability of Concepts
GPars provides a lot of concepts to pick from. We're continuously building and updating a page that tries to help user choose the right abstraction for their tasks at hands. Please, refer to the Concepts compared page for details.To briefly summarize the suggestions, below you can find basic guide-lines distilled from the page:- You're looking at a collection, which needs to be iterated or processed using one of the many beautiful Groovy collections method, like each() , collect() , find() and such. Proposing that processing each element of the collection is independent of the other items, using GPars parallel collections can be recommended.
- If you have a long-lasting calculation , which may safely run in the background, use the asynchronous invocation support in GPars. You can also benefit, if your long-calculating closures need to be passed around and yet you'd like them not to block the main application thread.
- You need to parallelize an algorithm at hand. You can identify sub-tasks and you're happy to explicitly express the options for parallelization. You create internally sequential tasks, each of which can run concurrently with the others, providing they all have a way to exchange data at some well-defined moments through communication channels with safe semantics. Use GPars dataflow tasks, variables and streams.
- You can't avoid shared mutable state. Multiple threads will be accessing shared data and (some of them) modifying the data. Traditional locking and synchronized approach feels too risky or unfamiliar. Go for agents, which will wrap your data and serialize all access to it.
- You're building a system with high concurrency demands. Tweaking a data structure here or task there won't cut it. You need to build the architecture from the ground up with concurrency in mind. Message-passing might be the way to go.
- Groovy CSP will give you highly deterministic and composable model for concurrent processes.
- If you're trying to solve a complex data-processing problem, consider GPars dataflow operator to build a data flow network.
- Actors will shine if you need to build a general-purpose, highly concurrent and scalable architecture.