Using the ForkJoin Framework in Eclipse
More extensive notes can be found on Notes on the Java ForkJoin Framework for CSE332.
- Download the
jsr166.jar
file here
- Create your Java project as usual in Eclipse.
- In the project, choose Project → Properties from the menu. Under "Java Compiler" check "Enable project specific settings"
and make sure the choice is Java 1.6 (earlier versions will not work).
- Drag & drop the
jsr166.jar
file you just downloaded onto the Java Project you just created in the Package Explorer window of Eclipse.
- Alternatively, instead of drag and drop, you can also right-click on the project in the File Explorer, and select "Import..."→"File System" and navigate to the .jar file, select it, make sure "Create selected folders only" is selected, and click "Finish".
- Right-click the newly-added .jar file, and choose "Add to Build Path."
- Under Run → Configurations, create a new configuration. Under
Arguments, you are used to putting program arguments in the top and
that is as usual. But also under "VM arguments" on the bottom you need to enter:
-Xbootclasspath/p:jsr166.jar
exactly like that.
- Create/add your class (New→Class) with a
main
method you can run:
- Your class should extend
RecursiveTask<T>
or RecursiveAction
- Once in your program, and only once, before you start parallelizing, you need to startup the forkjoin pool. It can be done in main, or you can just have it as a public static variable:
static
final ForkJoinPool fjPool=new ForkJoinPool();
- In main(), you start up the entire process via
fjPool.invoke(new ForkJoinTemplate(a,0,num))
, or
whatever its arguments are, assuming your newly created class's name is, e.g. ForkJoinTemplate
.
Troubleshooting
Having trouble? Possible issues:
- Getting a
SecurityException
when you run the program: you did not add the .jar file properly. Try following these instructions again, or try the instructions for the older versions of Eclipse on this page.
NoClassDefFoundError
or something similar when you run the program: may mean that the 'VM Argument'
isn't set correctly; it must be exactly '-Xbootclasspath/p:jsr166.jar'
- Out of memory, stack overflow, etc.: It's running, but runs out of memory (as you may have divined from the error message); up the cutoff, cut down on the size of the input, etc. Another
possibility is that it's not switching to your sequential case properly; try checking that code