2:20 am - Tuesday November 13, 2018

Thread Example program for start()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
//Thread Example program for start() method
/**
@author:candidjava.com
@description:program for start() method in thread
*/
class Sample implements Runnable {
	public void run() {
		for (int i = 0; i < 5; i++) {
			// print the result
			System.out.println(i);
		}
	}
}

public class sam {
	public static void main(String args[]) {
		// create a object
		Sample s1 = new Sample();
		Thread t1 = new Thread(s1);
		// starts a thread
		t1.start();
		for (int i = 0; i < 5; i++) {
			System.out.println(i);
		}
	}
}

OUTPUT:
0
1
2
3
4
0
1
2
3
4

Filed in: Z-A All Java Codes

Comments are closed.