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 7661a27

Browse files
Add files via upload
1 parent 12368c6 commit 7661a27

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

‎Multithreading/Multithreading2.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package Multithreading;
2+
3+
/**
4+
* Multithreading2
5+
*/
6+
class DemoThread extends Thread {
7+
DemoThread()
8+
{
9+
super("Demo Thread");
10+
System.out.println("Child Thread:"+this);
11+
start();
12+
}
13+
public void run() {
14+
try{
15+
for(int i=8;i>0;i--)
16+
{
17+
System.out.println("Child:"+i);
18+
Thread.sleep(500);
19+
}
20+
}
21+
catch(InterruptedException e)
22+
{
23+
System.out.println("Child Interrupted");
24+
}
25+
System.out.println("Child Exiting");
26+
}
27+
28+
}
29+
class Multithreading2 {
30+
public static void main(String[] args) {
31+
new DemoThread();
32+
try{
33+
for(int i=5;i>0;i--)
34+
{
35+
System.out.println("Main:"+i);
36+
Thread.sleep(1000);
37+
}
38+
}
39+
catch(InterruptedException e)
40+
{
41+
System.out.println("Main Interrupted");
42+
}
43+
System.out.println("Main Exiting");
44+
}
45+
46+
}

0 commit comments

Comments
(0)

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