Skip to content

Commit a5a59da

Browse files
joints in threads
1 parent 5f5a8fa commit a5a59da

File tree

9 files changed

+89
-0
lines changed

9 files changed

+89
-0
lines changed

Theads/bin/Threads/Demo.class

513 Bytes
Binary file not shown.
611 Bytes
Binary file not shown.
610 Bytes
Binary file not shown.

Theads/bin/Threads/Jointkeyword.class

1.54 KB
Binary file not shown.

Theads/bin/Threads/myclass.class

1.22 KB
Binary file not shown.

Theads/bin/module-info.class

151 Bytes
Binary file not shown.

Theads/src/Threads/Demo.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package Threads;
2+
3+
4+
class myclass extends Thread {
5+
6+
7+
public void run() {
8+
for(int i = 0; i <10; i++) {
9+
System.out.println(Thread.currentThread().getId() + "value = "+i);
10+
}
11+
try {
12+
Thread.sleep(100);
13+
} catch (InterruptedException e) {
14+
// TODO Auto-generated catch block
15+
e.printStackTrace();
16+
}
17+
}
18+
19+
}
20+
21+
22+
23+
public class Demo {
24+
25+
public static void main(String[] args) {
26+
myclass class1 = new myclass();
27+
class1.start();
28+
myclass class2 = new myclass();
29+
class2.start();
30+
31+
}
32+
33+
}

Theads/src/Threads/Jointkeyword.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package Threads;
2+
3+
public class Jointkeyword {
4+
private static int count = 0;
5+
public static void main(String[] args) {
6+
Thread t1 = new Thread(new Runnable() {
7+
8+
@Override
9+
public void run() {
10+
// TODO Auto-generated method stub
11+
for (int i=0; i<=1000; i++) {
12+
count++;
13+
14+
}
15+
16+
}
17+
18+
19+
});
20+
21+
Thread t2 = new Thread(new Runnable() {
22+
23+
@Override
24+
public void run() {
25+
// TODO Auto-generated method stub
26+
for (int i =0; i>= 100; i++) {
27+
count++;
28+
}
29+
}
30+
});
31+
32+
33+
t1.start();
34+
t2.start();
35+
// System.out.println("value :"+ count);
36+
37+
try {
38+
t1.join();
39+
t2.join();
40+
} catch (InterruptedException e) {
41+
// TODO Auto-generated catch block
42+
e.printStackTrace();
43+
}
44+
// t2.join();
45+
System.out.println("value :-" + count);
46+
}
47+
48+
}

Theads/src/module-info.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
*
3+
*/
4+
/**
5+
*
6+
*/
7+
module TheadsINJava {
8+
}

0 commit comments

Comments
 (0)