Oct 08

Create a new Instance of Thread and call its start() method to start it.
You give the Thread constructor some instance that implements the Runnable interface. Once started the Thread will call the Runnable instances run() method is a separate thread.


Thread thread = new Thread(new Runnable()
{
   public void run()
   {
       // this will be run in a separate thread

       doSomething();
   }
});

// start the thread

thread.start(); 

written by objects \\ tags:


One Response to “How do I execute a method in a new thread using Java?”

  1. henryk Says:

    thanks, it is exactly what i was looking for

Leave a Reply

You must be logged in to post a comment.