Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should become familiar with the <a href="http://java.sun.com/j2se/6/docs/api/index.html?java/util/concurrent/package-summary.html" rel="nofollow noreferrer">java.util.concurrent</a> package. It has simple and robust primitives for parallel programming upon which to base higher-level libraries. One example of such a library is <a href="http://functionaljava.org" rel="nofollow noreferrer">Functional Java</a>, which has <a href="http://functionaljava.googlecode.com/svn/artifacts/2.20/javadoc/fj/control/parallel/ParModule.html" rel="nofollow noreferrer">an easy-to-use module for parallel programming</a>.</p> <p>For example, here is the canonical MapReduce example written using Functional Java. It counts the number of words in a set of documents, assuming documents are Streams of characters:</p> <pre><code>public static long countWords(final List&lt;Stream&lt;Character&gt;&gt; documents, final ParModule m) { return m.parFoldMap(documents, new F&lt;Stream&lt;Character&gt;, Long&gt;() { public Long f(final Stream&lt;Character&gt; document) { return (long)fromStream(document).words().length(); }}, longAdditionMonoid) .claim(); } </code></pre> <p>To instantiate ParModule, you give it a parallel Strategy. You can implement your own Strategies, or use one that's supplied. Here's one that uses a fixed pool of 16 threads:</p> <pre><code>ExecutorService pool = newFixedThreadPool(16); ParModule m = parModule(executorStrategy(pool)); </code></pre> <p>You need the following imports for the example above:</p> <pre><code>import fj.F; import fj.data.Stream; import fj.control.parallel.ParModule; import static fj.control.parallel.ParModule.parModule; import static fj.pre.Monoid.longAdditionMonoid; import static fj.data.LazyString.fromStream; import static fj.control.parallel.Strategy.executorStrategy; import static java.util.concurrent.Executors.newFixedThreadPool; import java.util.concurrent.ExecutorService; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload