aspose file tools*
The moose likes Features new in Java 7 and the fly likes Error when using new ForkJoin feature Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "Error when using new ForkJoin feature" Watch "Error when using new ForkJoin feature" New topic
Author

Error when using new ForkJoin feature

Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

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

Joined: Aug 16, 2005
Posts: 14156
    
  19

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

Thank you . I changed my main method to look like this and it works:

 
Consider Paul's rocket mass heater.
 
subject: Error when using new ForkJoin feature