File tree 4 files changed +123
-3
lines changed
4 files changed +123
-3
lines changed Original file line number Diff line number Diff line change @@ -129,9 +129,44 @@ It is used to develop rich internet applications. It uses a light-weight user in
129
129
| [ MultiThreading] ( https://github.com/connectaman/Java_Notes_and_Programs/blob/master/src/Multithreading/multithreading.md ) |
130
130
| [ Life Cycle of Thread] ( https://github.com/connectaman/Java_Notes_and_Programs/blob/master/src/Multithreading/LifeCycle.md ) |
131
131
| [ Create Thread] ( https://github.com/connectaman/Java_Notes_and_Programs/blob/master/src/Multithreading/CreateThread.md ) |
132
- | [ Thread Sleep] ( ) |
132
+ | [ Thread Sleep] ( https://github.com/connectaman/Java_Notes_and_Programs/blob/master/src/Multithreading/ThreadSleep.md ) |
133
+ | [ run() Method] ( ) |
133
134
| [ ] ( ) |
134
135
| [ ] ( ) |
136
+ | [ ] ( ) |
137
+ | [ ] ( ) |
138
+ | [ ] ( ) |
139
+ | [ ] ( ) |
140
+ | [ ] ( ) |
141
+ | [ ] ( ) |
142
+ | [ ] ( ) |
143
+ | [ ] ( ) |
144
+ | [ ] ( ) |
145
+ | [ ] ( ) |
146
+ | [ ] ( ) |
147
+ | [ ] ( ) |
148
+ | [ ] ( ) |
149
+ | [ ] ( ) |
150
+ | [ ] ( ) |
151
+ | [ ] ( ) |
152
+ | [ ] ( ) |
153
+ | [ ] ( ) |
154
+ | [ ] ( ) |
155
+ | [ ] ( ) |
156
+ | [ ] ( ) |
157
+ | [ ] ( ) |
158
+ | [ ] ( ) |
159
+ | [ ] ( ) |
160
+ | [ ] ( ) |
161
+ | [ ] ( ) |
162
+ | [ ] ( ) |
163
+ | [ ] ( ) |
164
+ | [ ] ( ) |
165
+ | [ ] ( ) |
166
+ | [ ] ( ) |
167
+ | [ ] ( ) |
168
+ | [ ] ( ) |
169
+
135
170
136
171
137
172
Original file line number Diff line number Diff line change
1
+ ### Java Local inner class
2
+
3
+ ##### Java local inner class example
4
+
5
+ ``` java
6
+ public class localInner1 {
7
+ private int data= 30 ;// instance variable
8
+ void display (){
9
+ class Local {
10
+ void msg (){System . out. println(data);}
11
+ }
12
+ Local l= new Local ();
13
+ l. msg();
14
+ }
15
+ public static void main (String args []){
16
+ localInner1 obj= new localInner1();
17
+ obj. display();
18
+ }
19
+ }
20
+ ```
21
+ Output
22
+ ```
23
+ 30
24
+ ```
Original file line number Diff line number Diff line change
1
+ ### What if we call run() method directly instead start() method?
2
+
3
+
4
+ - Each thread starts in a separate call stack.
5
+ - Invoking the run() method from main thread, the run() method goes onto the current call stack rather than at the beginning of a new call stack.
6
+
7
+ ---------
8
+
9
+ ``` java
10
+ class TestCallRun1 extends Thread {
11
+ public void run (){
12
+ System . out. println(" running..." );
13
+ }
14
+ public static void main (String args []){
15
+ TestCallRun1 t1= new TestCallRun1 ();
16
+ t1. run();// fine, but does not start a separate call stack
17
+ }
18
+ }
19
+ ```
20
+ Output
21
+ ```
22
+ Output:running...
23
+ ```
24
+
25
+ ![ ] ( https://static.javatpoint.com/images/callstack1.JPG )
26
+ ##### Problem if you direct call run() method
27
+
28
+ -------
29
+
30
+ ``` java
31
+ class TestCallRun2 extends Thread {
32
+ public void run (){
33
+ for (int i= 1 ;i< 5 ;i++ ){
34
+ try {Thread . sleep(500 );}catch (InterruptedException e){System . out. println(e);}
35
+ System . out. println(i);
36
+ }
37
+ }
38
+ public static void main (String args []){
39
+ TestCallRun2 t1= new TestCallRun2 ();
40
+ TestCallRun2 t2= new TestCallRun2 ();
41
+
42
+ t1. run();
43
+ t2. run();
44
+ }
45
+ }
46
+ ```
47
+ Output
48
+ ```
49
+ Output: 1
50
+ 2
51
+ 3
52
+ 4
53
+ 5
54
+ 1
55
+ 2
56
+ 3
57
+ 4
58
+ 5
59
+ ```
You can’t perform that action at this time.
0 commit comments