File tree 3 files changed +40
-4
lines changed
src/main/java/com/learn/threading/daemon
3 files changed +40
-4
lines changed Original file line number Diff line number Diff line change 1
- package com .learn .threading .daemon ;public class App {
1
+ package com .learn .threading .daemon ;
2
+
3
+ public class App {
4
+
5
+ public static void main (String [] args ) {
6
+
7
+ Thread daemon = new Thread (new DaemonRunnable ());
8
+ if (!daemon .isDaemon ()) {
9
+ daemon .setDaemon (true );
10
+ }
11
+
12
+ Thread worker = new Thread (new WorkerRunnable ());
13
+
14
+ daemon .start ();
15
+ worker .start ();
16
+ }
2
17
}
Original file line number Diff line number Diff line change 1
- package com .learn .threading ;
1
+ package com .learn .threading . daemon ;
2
2
3
- public class DeamonThread {
3
+ public class DaemonRunnable implements Runnable {
4
+
5
+ @ Override
6
+ public void run () {
7
+ try {
8
+ // infinite loop
9
+ while (true ) {
10
+ System .out .println ("Daemon thread is running..." );
11
+ Thread .sleep (1000 );
12
+ }
13
+ } catch (InterruptedException e ) {
14
+ e .printStackTrace ();
15
+ }
16
+
17
+
18
+ }
4
19
}
Original file line number Diff line number Diff line change 1
- package com .learn .threading .daemon ;public class WorkerThread {
1
+ package com .learn .threading .daemon ;
2
+
3
+ public class WorkerRunnable implements Runnable {
4
+ @ Override
5
+ public void run () {
6
+ System .out .println ("Worker thread is running..." );
7
+ }
2
8
}
You can’t perform that action at this time.
0 commit comments