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.
As other answers have indicated you probably just want to pass in `Runnable`s or `Callable`s and use those as the basis for executing the method.

However, if you really want to pass around methods than you can use the [Reflection API](http://docs.oracle.com/javase/tutorial/reflect/member/methodInvocation.html) to accomplish this. It's somewhat cumbersome, but it is definitely doable.

```
public void spawn(final Method callme, final Object objectThatMethodIsAMemberOf, final Object...args) {
  new Thread() {
    @Override
    public void run() {
      try {
        callme.invoke(objectThatMethodIsAMemberOf, args);
      } catch(Exception e) {
        // A bunch of things can go wrong for example
        // you call the method on the wrong type of object
        // you supply the wrong number and/or type of arguments
        // the method is private and you don't have permission to call it
        // the method runs, but throws an exception
        // probably some more that I'm forgetting
      }
    }
  }.start()
}

```