Thread is a process in execution which can be scheduled or managed. A normal Java program by default has a main thread which start executing public static void main(String[] s) method. When we launch our program by java.exe or any other launcher it is invoked. But here we are suppose to control or maintain the single threaded application.

To schedule/manage any thread we must have object of Thread class. As such main thread is not created by developer we have to get the object from Runtime by calling a simple method.

class mainThread
{
	public static void main(String[] s)
	{
		Thread t = Thread.currentThread();
	}
}

Now object “t” can be used to call any method of Thread class. Which will ultimately control the main Thread. e.g.

class mainThread
{
	public static void main(String[] s) throws InterruptedException
	{
		Thread t = Thread.currentThread();
		System.out.println("Thread Started");
		t.sleep(1000);
		System.out.println("After Sleep");
	}
}

On calling t.sleep(1000) method the execution will be paused for 1second and then it will execute further. Method sleep(int) throws an InterruptedException which can be handled by applying “throws InterruptedException” clause.

If we really want to track the execution, We can print the Date object as below:

Single Thread Date Printing