Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A JRuby extension/wrapper around the Java 7 Fork/Join framework

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 javalib
Octocat-spinner-32 lib
Octocat-spinner-32 src
Octocat-spinner-32 README.md
Octocat-spinner-32 build.xml
Octocat-spinner-32 default.build.properties
Octocat-spinner-32 forkjoin.gemspec
README.md

forkjoin for JRuby

This is a small extension that wraps the JSR166y "Fork/Join" framework in an efficient way for JRuby.

Example

require 'forkjoin'

pool = ForkJoin::Pool.new

# FORK

# Add a job (a proc) to the pool for each line
map_futures = pool.invoke_all(
  ARGF.each_line.map{|line| ->{line.split.map{|word| [word,1]}}}
)

# Get aggregate results
counts = map_futures.map(&:get).inject({}) {|map, value|
  value.each {|k,v| (map[k] ||= []) << v}
  map
}

# JOIN

# Add a job to the pool for each count in the map
reduced_futures = pool.invoke_all(
  counts.map{|k, vs| ->{[k, vs.size]}}
)

# Print out results (or you could "reduce" some other way)
reduced_futures.map(&:get).each{|value|
  puts "%s %d\n" % value
}
Something went wrong with that request. Please try again.