Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Fork/Join in slow motion

DZone's Guide to

Fork/Join in slow motion

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

Have you ever wondered how fork/join algorithm really works? You can read a description but it is much better to actually see how the tasks are split, how the threads process them, how work stealing works and so on. And that’s exactly what we have done on the last GPars Hackathon. We have created demo that visualizes fork/join in slow motion.

THE DEMO

(alternatively you can download and execute this jar

You can notice several things

  1. A thread stays in its column. Threads do not compete, each of them works on its part of the problem.
  2. If a thread is forced to steal some work it takes a big chunk so it does not have to go stealing soon again.
  3. It does not run in the sandbox. Th jsr166y library uses sun.misc.Unsafe which is not part of public SDK API. That’s why you have to trust my self-signed certificate.

Source codes are available here ( Groovy, Java). The demo was brought to you by me, Jety and V áclav.

Are you using Bitbucket to accomplish your company's mission? Share your company’s mission with #Forthecode for a chance to be featured on our homepage, our social media channels, or win a free t-shirt!

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}