A few weeks ago I updated my age to be a factor of 2 and 5.  It is the perfect age to reflect what life is all about.  Some men don a leather jacket and ride around on a Harley.  But as a geek I know exactly where to turn - my beloved computer.  

I needed a long-running method for the new concurrency course I am writing.  Something that would take about 15 seconds and that would keep the CPU busy at 100%.  Also, since life throws us random events, we would have to include a call to Math.random() in the calculation.  In my next article I will explain why Math.random() is dead, long live Java 7, but for now we will call it in order to be super slow.

public class MeaningOfLife {
  public static String findOutWhatLifeIsAllAbout() {
    int meaning = 0;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 20; j++) {
        for (int k = 0; k < 300; k++) {
          for (int m = 0; m < 7000; m++) {
            meaning += Math.random() + 1;
          }
        }
      }
    }
    return String.valueOf(meaning).replaceAll("0*$", "");
  }

  public static void main(String[] args) {
    System.out.println(findOutWhatLifeIsAllAbout());
  }
}

Think about what the output should be before you run it. Then try it out, preferably with the -server switch. On my machine it takes 15 seconds to find the meaning of life with -server and 25 seconds with -client. Patience is apparently a virtue, though I would not be able to confirm or deny that.  Never had patience, which is why I always want the fastest meanest computer that I can get.

The question is: Why is it giving this result? And why does it even compile?