14-01-2010, 05:35 PM | #1 |
Member
Join Date: Dec 2009
Posts: 152
Rep Power: 15 |
Difference between run() and start() methods in Java Threads
For Java, the run() method is just another method; so, you can execute it directly, in which case it will be executed in the calling thread and not in its own thread. Code:
public class ThreadDemo { public static void main(String[] args) { Counter ct = new Counter(); ct.run(); //ct.start(); System.out.println("The thread has been started"); } } class Counter extends Thread { public void run() { for ( int i=1; i<=5; i++) { System.out.println("Count: " + i); } } } |
Bookmarks |
Tags |
threads |
|
|