Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Error when using new ForkJoin feature  RSS feed

 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I was experimenting with the new Fork/Join "task stealing" feature described at http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/RecursiveAction.html

Here is my implementation of the IncremementTask from that page:



This code generates the following error and I don't understand why:



beyond that, how can a programmer begin to estimate the thresholds that would be reasonable for breaking off tasks in this way?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15860
80
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're creating a RecursiveAction but it looks like you're not really using the fork-join framework.

You have to create a ForkJoinPool and let it execute your tasks, in line 12 of main(), instead of calling compute() directly.

Here's an example.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you . I changed my main method to look like this and it works:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!