Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error when using new ForkJoin feature

 
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
Saloon Keeper
Posts: 15207
36
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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic