Question: Using Java, is there a way to reference a method and have spawn off into a thread dynamically?

For example, if you have a method called `spawn()` which would take a parameter of another method reference and it would then spawn off a thread which would run the referenced method. I imagine the code would look something like:

```
void spawn(**wayToReferenceANumberOfDifferentMethods currentMethodToLaunch**) {
    new Thread(){
        public void run() {
            // **way to launch the currentMethodToLaunch**
        }
    }.start();
}

```

In order for the above to work, I think I would need to be able to reference a type of `method`. If this isn't possible, why is that so?

Answer: 
Strictly speaking? No. Java is not a functional language, methods are not objects and cannot be passed as parameters.

However, this sort of general behavior can be accomplished with an `ExecutorService` and `Runnable`/`Callable`s.

Take a look at the java doc for [ExecutorService](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html).

**Edit**

Also, it's possible to abstract asynchronous execution using various frameworks. For example, using the @Async annotation in the Spring framework.
You can pass an object that implements Runnable to the spawn method. 

```
void spawn(Runnable myRunnable) {
    Thread thread = new Thread(myRunnable); 
    thread.start();
}

```

You can have multiple classes that implement the Runnable interface, each doing something different. The object you pass to the spawn method would determine which one of them would actually run. 

Here is what the class that implements Runnable would look like:

```
public class MyClass implements Runnable 
{   
  public void run()     
  {
     // do what you need here
  }
} 

```

Until Java 8, interfaces were used to "pass methods around", like described above. With Java 8, you have Lambda expressions, which allow you to simulate this behavior better.