You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
959 B
Java

import java.util.*;
class MyThread implements Runnable
{
private Thread t;
private String ThreadName;
MyThread(String name)
{
ThreadName = name;
}
public void run()
{
System.out.println(ThreadName+" is starting..");
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
System.out.println(ThreadName+"interrupted");
}
System.out.println(ThreadName+" is stopping..");
}
public void start()
{
if(t == null)
{
t = new Thread(this, ThreadName);
t.start();
}
}
}
class Test
{
public static void main(String[] args)
{
MyThread m1 = new MyThread("yo dudes");
m1.start();
MyThread m2 = new MyThread("yo buddies again");
m2.start();
}
}