• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Real World Example for Fork/Join with Java SE 7

 
Ranch Hand
Posts: 48
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeff, Can you provide us a real world example of Fork/Join feature usage of Java 7, which explain how the work breakdown happens and how the work stealing algorithm works inside?
 
Author
Posts: 86
5
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shiv,

Beginning Java 7 presents a matrix multiplication example of fork/join. There are many real world examples that use matrix multiplication -- see http://math.stackexchange.com/questions/41706/practical-uses-of-matrix-multiplication for some of them.

You might also want to check out stackoverflow.com's "How can I show that in Java Fork/Join framework work-stealing occurs?" topic (http://stackoverflow.com/questions/14076890/how-can-i-show-that-in-java-fork-join-framework-work-stealing-occurs).

All the best.

Jeff
 
Shiv Swaminathan
Ranch Hand
Posts: 48
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jeff for the examples.

I have some follow-up questions

When using fork/join for doing recursive multiplication or linear computing, won't there be problem if the order of the computation is not followed.

For eg: Lets take Fibonacci Series computation (Assuming we are going to use make the multiplication as two numbers as the Recursive task)
The result of one thread's computation is needed for the next thread, and we dont want to duplicate the computation of another thread also.

Does fork/join help here?
Can we use fork/join for all kind of recursive task even when there are dependencies between the results of the recursive task and when order of execution needs to be maintained.
Should we consider some guidelines before deciding to use fork/join or identifying a Recursive Task.

Also please explain me how does Java do the real work stealing?
 
Jeffrey Friesen
Author
Posts: 86
5
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shiv,

Alex Miller points out in his "Comparing concurrent frameworks" blog post (http://tech.puredanger.com/2011/01/14/comparing-concurrent-frameworks/comment-page-1/) that the fork/join framework handles dependencies. I recommend that you read Doug Lea's "A Java Fork/Join Framework" paper (http://gee.cs.oswego.edu/dl/papers/fj.pdf) to learn more about this framework and work stealing.

All the best.

Jeff
 
Shiv Swaminathan
Ranch Hand
Posts: 48
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh Thank you Jeff.
Both the links you provided are really good.
I'm also going to experiment a program hands-on to show how dependencies are handled in Fork/Join.

Because looks like we have to programmatically handle it using the api's provided.

"Express dependencies directly using the RecursiveTask apis for fork, join, invoke, etc."
 
reply
    Bookmark Topic Watch Topic
  • New Topic