Threads

From Suhrid.net Wiki
Revision as of 22:58, 8 June 2011 by Suhridk (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
  • Think of Thread as the "worker" and Runnable as the job.
  • Define work to be done in a class that implements Runnable.
  • Instantiate the thread using the runnable object and then start() it.
class Job implements Runnable {
     public void run() {
         //work to be performed in  a separate thread.
     }
}

Job j = new Job();
Thread t = new Thread(j);

t.start();