Embed presentation
Downloaded 21 times
![JAVA WEEK9(A)
/* Week 9 : a) Write a Java program that creates three threads. First thread
displays “Good Morning” every one second, the second thread displays “Hello” every
two seconds and the third thread displays “Welcome” every three seconds. */
class tst implements Runnable
{
String name;
Thread t;
Arun(String threadname)
{
name = threadname;
t = new Thread(this, name);
System.out.println("newThread : " +t);
t.start();
}
public void run()
{
try
{
for(int i=5;i > 0;i--)
{
System.out.println(name + ": " + i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println(name + "Interrupted");
}
System.out.println(name + "exiting");
}
}
class LabPro16
{
public static void main(String args[])
{
new tst("Good Morning");
new tst("Hello");
new tst("Welcome");
try
{
Thread.sleep(10000);
}
catch(InterruptedException e)
{
System.out.println("Main thread Interrupted");
}
System.out.println("Main thread exiting");
}
}
Page 1](https://image.slidesharecdn.com/javaweek9a-notepad-100321092739-phpapp02/75/Java-Week9-A-Notepad-1-2048.jpg)

The document describes a Java program that creates three threads. The first thread displays "Good Morning" every one second. The second thread displays "Hello" every two seconds. The third thread displays "Welcome" every three seconds. The program implements three threads using the Runnable interface that each print a message on a different interval before exiting.
![JAVA WEEK9(A)
/* Week 9 : a) Write a Java program that creates three threads. First thread
displays “Good Morning” every one second, the second thread displays “Hello” every
two seconds and the third thread displays “Welcome” every three seconds. */
class tst implements Runnable
{
String name;
Thread t;
Arun(String threadname)
{
name = threadname;
t = new Thread(this, name);
System.out.println("newThread : " +t);
t.start();
}
public void run()
{
try
{
for(int i=5;i > 0;i--)
{
System.out.println(name + ": " + i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println(name + "Interrupted");
}
System.out.println(name + "exiting");
}
}
class LabPro16
{
public static void main(String args[])
{
new tst("Good Morning");
new tst("Hello");
new tst("Welcome");
try
{
Thread.sleep(10000);
}
catch(InterruptedException e)
{
System.out.println("Main thread Interrupted");
}
System.out.println("Main thread exiting");
}
}
Page 1](https://image.slidesharecdn.com/javaweek9a-notepad-100321092739-phpapp02/75/Java-Week9-A-Notepad-1-2048.jpg)