-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththreadrunnableinterface.java
More file actions
57 lines (53 loc) · 942 Bytes
/
Copy paththreadrunnableinterface.java
File metadata and controls
57 lines (53 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.*;
public class threadrunnableinterface
{
public static void main(String[] args)
{
Thread clock=new countdown();
ArrayList<Runnable> a=new ArrayList<Runnable>();
a.add(new Launchevent(16,"Flood The Pad!"));
a.add(new Launchevent(6,"Start Engines!"));
a.add(new Launchevent(0,"LiftOff!"));
clock.start();
for(Runnable e :a)
{
new Thread(e).start();
}
}
}
class Launchevent implements Runnable
{
private int time;
private String message;
public Launchevent(int time,String message)
{
this.time=time;
this.message=message;
}
public void run()
{
try
{
Thread.sleep(20000-(time*1000));
}
catch(InterruptedException E)
{}
System.out.println(message);
}
}
class countdown extends Thread
{
public void run()
{
for(int i=20;i>=0;i--)
{
System.out.println("T minus "+i+" seconds");
try
{
Thread.sleep(1000);
}
catch(InterruptedException E)
{}
}
}
}