File tree Expand file tree Collapse file tree 4 files changed +125
-0
lines changed Expand file tree Collapse file tree 4 files changed +125
-0
lines changed Original file line number Diff line number Diff line change
1
+ class MyThread extends Thread {
2
+
3
+ public void run () {
4
+
5
+ System .out .println (Thread .currentThread ());
6
+ }
7
+ }
8
+ class Main {
9
+
10
+ public static void main (String [] args ) throws InterruptedException {
11
+
12
+ System .out .println (Thread .currentThread ());
13
+
14
+ MyThread obj = new MyThread ();
15
+ obj .start ();
16
+
17
+ Thread .sleep (1000 );
18
+
19
+ Thread .currentThread ().setName ("Core2Web" );
20
+
21
+ System .out .println (Thread .currentThread ());
22
+ }
23
+ }
24
+
Original file line number Diff line number Diff line change
1
+ class MyThread extends Thread {
2
+
3
+ public void run () {
4
+
5
+ for (int i = 0 ;i < 10 ; i ++) {
6
+
7
+ System .out .println ("In Thread-0" );
8
+
9
+ try {
10
+
11
+ Thread .sleep (1000 ,500000 );
12
+ } catch (InterruptedException obj ) {
13
+
14
+ System .out .println ("Exception Occure" );
15
+ }
16
+ }
17
+ }
18
+ }
19
+
20
+ class Main {
21
+
22
+ public static void main (String [] args ) throws InterruptedException {
23
+
24
+ MyThread obj = new MyThread ();
25
+ obj .start ();
26
+
27
+ for (int i = 0 ;i < 10 ; i ++) {
28
+
29
+ System .out .println ("In Main" );
30
+ Thread .sleep (1000 );
31
+ }
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ class MyThread extends Thread {
2
+
3
+ public void run () {
4
+
5
+ for (int i = 0 ; i < 5 ; i ++) {
6
+
7
+ System .out .println ("In Thread-0" );
8
+ try {
9
+
10
+ Thread .sleep (1000 );
11
+ } catch (InterruptedException obj ) {
12
+
13
+ System .out .println ("Exception Occure" );
14
+ }
15
+ }
16
+ }
17
+ }
18
+
19
+ class Main {
20
+
21
+ public static void main (String [] args ) throws InterruptedException {
22
+
23
+ MyThread obj = new MyThread ();
24
+ obj .start ();
25
+
26
+ obj .join (3000 );
27
+
28
+ for (int i = 0 ; i < 5 ; i ++) {
29
+
30
+ System .out .println ("In Main" );
31
+ }
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ class MyThread extends Thread {
2
+
3
+ static Thread nmMain = null ;
4
+ public void run () {
5
+
6
+ try {
7
+
8
+ nmMain .join ();
9
+ } catch (InterruptedException obj ) {
10
+
11
+ System .out .println ("Exception Occure" );
12
+ }
13
+ System .out .println ("In Thread-0" );
14
+ }
15
+ }
16
+ class Main {
17
+
18
+ public static void main (String [] args ) {
19
+
20
+ MyThread .nmMain = Thread .currentThread ();
21
+
22
+ MyThread obj = new MyThread ();
23
+ obj .start ();
24
+
25
+ try {
26
+
27
+ obj .join ();
28
+ } catch (InterruptedException ie ) {
29
+
30
+ System .out .println ("Exception Occure" );
31
+ }
32
+
33
+ System .out .println ("IN Main" );
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments