File tree 1 file changed +57
-0
lines changed
1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ package Multithreading ;
2
+
3
+ class NewThread implements Runnable {
4
+ String name ;
5
+ Thread t ;
6
+ NewThread (String thdname )
7
+ {
8
+ name =thdname ;
9
+ t =new Thread (this ,name );
10
+ System .out .println ("New Thread:" +t );
11
+ t .start ();
12
+ }
13
+ public void run ()
14
+ {
15
+ try {
16
+ for (int i =5 ;i >0 ;i --)
17
+ {
18
+ System .out .println (name +":" +i );
19
+ Thread .sleep (500 );
20
+ }
21
+ }
22
+ catch (InterruptedException e )
23
+ {
24
+ System .out .println (name + " Interrupted" );
25
+ }
26
+ System .out .println (name +" exiting" );
27
+ }
28
+ }
29
+ /**
30
+ * MultiThreading6
31
+ */
32
+ class MultiThreading6 {
33
+ public static void main (String [] args ) {
34
+ NewThread ob1 =new NewThread ("Thread One" );
35
+ NewThread ob2 =new NewThread ("Thread Two" );
36
+ NewThread ob3 =new NewThread ("Thread Three" );
37
+ System .out .println ("Ob1 is Alive:" +ob1 .t .isAlive ());
38
+ System .out .println ("Ob2 is Alive:" +ob2 .t .isAlive ());
39
+ System .out .println ("Ob3 is Alive:" +ob3 .t .isAlive ());
40
+ try
41
+ {
42
+ ob1 .t .join ();
43
+ ob2 .t .join ();
44
+ ob3 .t .join ();
45
+ }
46
+ catch (InterruptedException e )
47
+ {
48
+ System .out .println ("Main Interrupted" );
49
+ System .out .println ("Ob1 is Alive:" + ob1 .t .isAlive ());
50
+ System .out .println ("Ob2 is Alive:" + ob2 .t .isAlive ());
51
+ System .out .println ("Ob3 is Alive:" + ob3 .t .isAlive ());
52
+ }
53
+
54
+ }
55
+
56
+
57
+ }
You can’t perform that action at this time.
0 commit comments