Click here to watch in Youtube :
Click the below Image to Enlarge
![]() |
| Java Tutorial : Java Threads (What if we call the run() method directly instead of start() method) |
![]() |
| Java Tutorial : Java Threads (What if we call the run() method directly instead of start() method) |
class DisplayThread extends Thread
{
public static void main(String args[])
{
DisplayThread displayThread = new DisplayThread();
/*
* fine, but does not start a separate call stack
*/
displayThread.run();
}
public void run()
{
System.out.println("Hello by ");
}
}
Hello by
DisplayNumberThread.javapublic class DisplayNumberThread extends Thread
{
public static void main(String[] args)
{
DisplayNumberThread displayNumberThread1 = new DisplayNumberThread();
DisplayNumberThread displayNumberThread2 = new DisplayNumberThread();
displayNumberThread1.run();
displayNumberThread2.run();
}
public void run()
{
for (int i = 1; i < 5; i++)
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println(i);
}
}
}
1
2
3
4
1
2
3
4
Click the below link to download the code:


No comments:
Post a Comment