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 7a7e798

Browse files
Add files via upload
1 parent 7d11317 commit 7a7e798

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

‎Misc Programmes/ThreeThread.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
class Multithread implements Runnable{
2+
long click=0;
3+
Thread t;
4+
private volatile boolean running =true;
5+
public Multithread(int p)
6+
{
7+
t=new Thread(this);
8+
t.setPriority(p);
9+
t.start();
10+
}
11+
public void run()
12+
{
13+
System.out.println("Thread Running:"+t);
14+
while(running)
15+
{
16+
if(click>10)
17+
{
18+
stop();
19+
}
20+
System.out.println(click++);
21+
}
22+
}
23+
public void stop()
24+
{
25+
running=false;
26+
}
27+
}
28+
/**
29+
* ThreeThread
30+
*/
31+
public class ThreeThread {
32+
33+
public static void main(String[] args) {
34+
Thread.currentThread().setPriority(10);
35+
Multithread th1=new Multithread(7);
36+
Multithread th2=new Multithread(5);
37+
Multithread th3=new Multithread(3);
38+
try{
39+
System.out.println("Sleeping main Thread");
40+
Thread.sleep(1000);
41+
}
42+
catch(InterruptedException e)
43+
{
44+
System.out.println("Interrupted:"+e);
45+
}
46+
th1.stop();
47+
th2.stop();
48+
th3.stop();
49+
try{
50+
th1.t.join();
51+
th2.t.join();
52+
th3.t.join();
53+
}
54+
catch(Exception e)
55+
{
56+
System.out.println("Interrupted:"+e);
57+
}
58+
System.out.println("Thread1:"+th1.click);
59+
System.out.println("Thread2:"+th2.click);
60+
System.out.println("Thread3:"+th3.click);
61+
62+
}
63+
}

0 commit comments

Comments
(0)

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