Splunk Completes Acquisition of Plumbr Learn more

To blog |

Java Puzzle – are you up for a challenge?

December 15, 2014 by Nikita Salnikov-Tarnovski Filed under: Performance

Java puzzlerIf you are anything like me, you have a sweet tooth for programming puzzlers. Ever since I first attended Joshua Bloch “Java Puzzlers” talk ten years ago, I have always enjoyed the feeling how a solution folds out throughout a well-crafted puzzle.

During the following decade, I have faced many real-world situations where knowledge about the nuances embedded into small puzzlers have helped me to solve real problems. So, besides being intellectually interesting, solving puzzles will also make you a better programmer. Now it is time for me to give my first try in creating a puzzle myself. Hopefully you are going to enjoy it as much as I have.

The puzzle is calculating a secret. Spoiler alert the repository now also contains the solution, so when solving it, avoid the “fast” package or it will spoil the fun. As you might guess, your goal is to discover the secret. With the current version of the application it is going to take ages. How much exactly, we honestly do not know, but on a typical desktop we are speaking about years. Besides being terribly slow, the current version of the puzzle also is leading you towards a wrong secret.

If you are up for the challenge then your goal is to decrease the running time of this application below 30 seconds and discover the secret along the way. If you are able to solve the secret, you will have eternal satisfaction, knowing that you were able to conquer the almighty Java Performance Beasts.

To give more incentive to solve the puzzle, we are also adding copies of the Joshua Bloch and Neal Gafter “Java Puzzler” book as prizes. If you are able to solve the puzzle before December 29, 2014 you stand a chance to win one of the three books.

UPDATE: the campaign is finished and the books have found their new owners. In total 312 people managed to discover the secret and 170 sent their solution to us. Thank you, job well done, hope you all enjoyed it!

Good luck with the puzzle!

ADD COMMENT

Comments

I would like to redo the challenge. Is it possible that you add the source file into the repository so I can run it offline. As the ec2 aws server is down.

Simulant

You can improve provided solution by modifying Worker.run by moving calculation out of synchronized block (only adding calculated secret should be within this block).

Wojciech Lozowicki

Downloading the file takes about 8 seconds!, When It is cached (need to hack one line in Main.java) total time can be less than few milliseconds on cheap laptop.

Bartosz Rybacki

As it is said in Readme, you are not allowed to change anything in internal package. So Main should remain untouched 🙂

Nikita Salnikov-Tarnovski Post author