File tree Expand file tree Collapse file tree 8 files changed +94
-0
lines changed
src/main/java/com/learn/threading Expand file tree Collapse file tree 8 files changed +94
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .learn .threading .daemon ;public class App {
2
+ }
Original file line number Diff line number Diff line change
1
+ package com .learn .threading ;
2
+
3
+ public class DeamonThread {
4
+ }
Original file line number Diff line number Diff line change
1
+ package com .learn .threading .daemon ;public class WorkerThread {
2
+ }
Original file line number Diff line number Diff line change
1
+ package com .learn .threading .deadLock ;
2
+
3
+ import com .learn .threading .util .TimerExit ;
4
+
5
+ public class SimpleDeadLock {
6
+
7
+ public static void main (String [] args ) {
8
+
9
+ // program will exit after 5000 milliseconds
10
+ TimerExit timerExit = new TimerExit (5000 );
11
+ timerExit .exitProgram ();
12
+ try {
13
+ Thread .currentThread ().join ();
14
+ } catch (InterruptedException e ) {
15
+ e .printStackTrace ();
16
+ }
17
+ System .exit (-1 );
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ package com .learn .threading .sequentialVsThreading ;
2
+
3
+ public class App {
4
+
5
+ public static void main (String [] args ) {
6
+
7
+ // creating runners
8
+ Runner r1 = new Runner ("Runner1" );
9
+ Runner r2 = new Runner ("Runner2" );
10
+
11
+ System .out .println ("Start --- Sequential Execution" );
12
+ // sequential executions
13
+ r1 .execute ();
14
+ r2 .execute ();
15
+ System .out .println ("End --- Sequential Execution" );
16
+
17
+ // creating threads
18
+ Thread t1 = new Thread (() -> {
19
+ r1 .execute ();
20
+ });
21
+ Thread t2 = new Thread (() -> {
22
+ r2 .execute ();
23
+ });
24
+
25
+ System .out .println ("Start --- Thread Execution" );
26
+ // thread executions
27
+ t1 .start ();
28
+ t2 .start ();
29
+
30
+ System .out .println ("End --- Thread Execution" );
31
+ }
32
+ }
Original file line number Diff line number Diff line change
1
+ package com .learn .threading .sequentialVsThreading ;
2
+
3
+ public class Runner {
4
+ String name ;
5
+
6
+ public Runner (String name ) {
7
+ this .name = name ;
8
+ }
9
+
10
+ public void execute () {
11
+ for (int i = 0 ; i < 10 ; i ++) {
12
+ System .out .println (this .name + "-" + i + " running in " + Thread .currentThread ().getName ());
13
+ }
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ package com .learn .threading ;
2
+
3
+ public class Incrementer implements Runnable {
4
+
5
+ public static int i ;
6
+ public static void increment (){
7
+ i ++;
8
+ }
9
+
10
+ @ Override
11
+ public void run () {
12
+ for (int j = 0 ; j <10 ; j ++) {
13
+ increment ();
14
+ }
15
+ System .out .println ("current value" +i );
16
+ }
17
+
18
+ }
Original file line number Diff line number Diff line change
1
+ package com .learn .threading .util ;public class TimerExit {
2
+ }
You can’t perform that action at this time.
0 commit comments