class NamedThread extends Thread
{
private String name; // The name of this thread.
public NamedThread(String name)
{ // Constructor gives name to thread.
super(name);
this.name = name;
System.out.println(this);
start();
}
public void run()
{ // The run method prints a message to standard output.
for (int i=1; i<=10;i++)
{
System.out.println("Greetings from : "+name);
}
System.out.println("End of child thread!");
}
}
class MultiThreadsTest
{
public static void main(String args[])
{
new NamedThread("Child Thread 1");
new NamedThread("Child Thread 2");
new NamedThread("Child Thread 3");
for (int i=1; i<=10;i++)
{
System.out.println("Main Thread ");
}
System.out.println("End of main thread!");
}
}
{
private String name; // The name of this thread.
public NamedThread(String name)
{ // Constructor gives name to thread.
super(name);
this.name = name;
System.out.println(this);
start();
}
public void run()
{ // The run method prints a message to standard output.
for (int i=1; i<=10;i++)
{
System.out.println("Greetings from : "+name);
}
System.out.println("End of child thread!");
}
}
class MultiThreadsTest
{
public static void main(String args[])
{
new NamedThread("Child Thread 1");
new NamedThread("Child Thread 2");
new NamedThread("Child Thread 3");
for (int i=1; i<=10;i++)
{
System.out.println("Main Thread ");
}
System.out.println("End of main thread!");
}
}
0 comments:
Post a Comment