Posts

Showing posts from October, 2015

Thread in Java - 01

Thread in Java - 01 A thread is a separate flow of execution, each execution is having a separate job during the execution. We can define a thread by extending java.lang.Thread class and implementing Runnable interface. Thread scheduler is part of JVM, It's responsible for scheduling Threads. That's if multiple threads are waiting to get the chance of execution, this execution order is decided by Thread scheduler. We can not expect an exact algorithm is followed by thread scheduler. It's varied from JVM to JVM, Hence we can not expect thread execution order under an exact output. Creating and starting a thread In this post, I am going to explain how to create a thread by using Thread class, how to start this created thread, also analyze possible cases. public class MyThread extends Thread {     @Override     public void run() {         for ( int i = 0; i < 10; i ++) {               System. out .println( "My Thread" );         }