Over a million developers have joined DZone.

Fork/Join in slow motion

DZone's Guide to

Fork/Join in slow motion

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

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.


(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.

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat


Opinions expressed by DZone contributors are their own.


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.


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

{{ parent.tldr }}

{{ parent.urlSource.name }}