Skip to content

Commit 8860173

Browse files
kcacademicpivovarit
authored andcommitted
BAEL-2187 - Adding files for the tutorial related to Java Yield (eugenp#5169)
1 parent 332061d commit 8860173

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • core-java-concurrency/src/main/java/com/baeldung/concurrent/yield
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.concurrent.yield;
2+
3+
public class ThreadYield {
4+
public static void main(String[] args) {
5+
Runnable r = () -> {
6+
int counter = 0;
7+
while (counter < 2) {
8+
System.out.println(Thread.currentThread()
9+
.getName());
10+
counter++;
11+
Thread.yield();
12+
}
13+
};
14+
new Thread(r).start();
15+
new Thread(r).start();
16+
}
17+
}

0 commit comments

Comments
 (0)