Skip to content

Commit 62ecdd8

Browse files
committed
Challenge 35.
Daemon Thread.
1 parent 26072ca commit 62ecdd8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package challenge31_40;
2+
3+
/**
4+
* Daemon thread : https://stackoverflow.com/questions/2213340/what-is-a-daemon-thread-in-java
5+
* is a thread that does not prevent the JVM from exiting.
6+
* an example of a daemon thread is the garbage collector.
7+
*/
8+
public class Challenge_35 {
9+
private static int nummer = 10;
10+
public static void main( String[] args ) {
11+
new MotorCycle("Harley Davidson").start();
12+
13+
MotorCycle motorCycle = new MotorCycle("Dodge Tomahawk");
14+
motorCycle.setPriority(Thread.MAX_PRIORITY);
15+
motorCycle.setDaemon(true);
16+
motorCycle.start();
17+
18+
MotorCycle yamaha = new MotorCycle("Yamaha");
19+
yamaha.setPriority(Thread.MIN_PRIORITY);
20+
yamaha.setDaemon(true);
21+
yamaha.start();
22+
}
23+
static class MotorCycle extends Thread {
24+
public MotorCycle( String name ) {
25+
super(name);
26+
}
27+
28+
@Override
29+
public void run() {
30+
nummer++;
31+
if (nummer==13)
32+
System.out.println(this.getName());
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)