programming-examples/java/MyThread.java

48 lines
959 B
Java
Raw Normal View History

2019-11-18 13:43:20 +01:00
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();
}
}