-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreads.java
More file actions
61 lines (53 loc) · 1015 Bytes
/
Threads.java
File metadata and controls
61 lines (53 loc) · 1015 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
58
/*
TODO: Threads
*/
public class Threads extends Thread
{
public void run()
{
System.out.println("Run is invoked by JVM after calling start()---Thread class");
for(int i = 0; i<=5; i++)
{
System.out.println(i);
try
{
Thread.sleep(10);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
System.out.println(Thread.currentThread().getName());
}
public static void main(String args[])
{
Threads obj = new Threads(), obj1 = new Threads(), obj2 = new Threads();
obj.start();
try
{
//obj.join();
obj.join(100);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
obj1.start();
obj2.start();
}
}
class Threads1 implements Runnable
{
public void run()
{
System.out.println("Run is invoked by JVM after calling start()---Runnable interface");
}
public static void main(String args[])
{
Threads ob = new Threads();
Thread obj = new Thread(ob);
obj.setDeamon(true);// Deamon thread
obj.start();
}
}