Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ffa4772

Browse files
Add files via upload
1 parent 317a416 commit ffa4772

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

‎Multithreading/MultiThreading6.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /