title: How to asynchronously call a method in Java
body: <p>I've been looking at <a href="http://golang.org/doc/effective_go.html#goroutines" rel="noreferrer">Go's goroutines</a> lately and thought it would be nice to have something similar in Java. As far as I've searched the common way to parallelize a method call is to do something like:</p>
  
  <pre><code>final String x = "somethingelse";
  new Thread(new Runnable() {
             public void run() {
                  x.matches("something");             
      }
  }).start();
  </code></pre>
  
  <p>Thats not very elegant. <strong>Is there a better way of doing this?</strong> I needed such a solution in a project so I decided to implement my own wrapper class around a async method call.</p>
  
  <p>I published my wrapper class in <a href="http://github.com/felipehummel/j-go" rel="noreferrer">J-Go</a>. But I don't know if it is a good solution. The usage is simple:</p>
  
  <pre><code>SampleClass obj = ...
  FutureResult&lt;Integer&gt; res = ...
  Go go = new Go(obj);
  go.callLater(res, "intReturningMethod", 10);         //10 is a Integer method parameter
  //... Do something else
  //...
  System.out.println("Result: "+res.get());           //Blocks until intReturningMethod returns
  </code></pre>
  
  <p>or less verbose:</p>
  
  <pre><code>Go.with(obj).callLater("myRandomMethod");
  //... Go away
  if (Go.lastResult().isReady())                //Blocks until myRandomMethod has ended
      System.out.println("Method is finished!");
  </code></pre>
  
  <p>Internally I'm using a class that implements Runnable and do some Reflection work to get the correct method object and invoking it.</p>
  
  <p>I want some opinion about my tiny library and on the subject of making async method calls like this in Java. Is it safe? Is there already a simplier way?</p>