File tree Expand file tree Collapse file tree 3 files changed +80
-0
lines changed Expand file tree Collapse file tree 3 files changed +80
-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
+ for (int i = 0 ; i < 10 ; i ++) {
6
+
7
+ System .out .println ("In Run" );
8
+ }
9
+ }
10
+ }
11
+ class Main {
12
+
13
+ public static void main (String [] args ) {
14
+
15
+ MyThread obj = new MyThread ();
16
+ obj .start ();
17
+
18
+ for (int i = 0 ; i < 10 ; i ++) {
19
+
20
+ System .out .println ("In main" );
21
+ }
22
+ }
23
+ }
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 run" );
8
+ try {
9
+
10
+ Thread .sleep (1000 );
11
+ } catch (InterruptedException obj ) {
12
+
13
+ System .out .println ("Exception Handled" );
14
+ }
15
+ }
16
+ }
17
+ }
18
+ class Main {
19
+
20
+ public static void main (String [] args ) {
21
+
22
+ MyThread obj = new MyThread ();
23
+ obj .start ();
24
+
25
+ for (int i = 0 ; i < 10 ; i ++) {
26
+
27
+ System .out .println ("In Main" );
28
+ try {
29
+
30
+ Thread .sleep (1000 );
31
+ } catch (InterruptedException ie ) {
32
+
33
+ System .out .println ("Exception Handled" );
34
+ }
35
+ }
36
+ }
37
+ }
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 ("Child Thread : " + Thread .currentThread ().getName ());
6
+ }
7
+ }
8
+ class Main {
9
+
10
+ public static void main (String [] args ) throws InterruptedException {
11
+
12
+ System .out .println ("Main Thread : " + Thread .currentThread ().getName ());
13
+
14
+ MyThread obj1 = new MyThread ();
15
+ obj1 .start ();
16
+
17
+ MyThread obj2 = new MyThread ();
18
+ obj2 .start ();
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments