BAEL-2187 - Adding files for the tutorial related to Java Yield (#5169)

This commit is contained in:
Kumar Chandrakant 2018-09-13 11:04:29 +05:30 committed by Grzegorz Piwowarek
parent 332061d8bd
commit 88601730d0
1 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,17 @@
package com.baeldung.concurrent.yield;
public class ThreadYield {
public static void main(String[] args) {
Runnable r = () -> {
int counter = 0;
while (counter < 2) {
System.out.println(Thread.currentThread()
.getName());
counter++;
Thread.yield();
}
};
new Thread(r).start();
new Thread(r).start();
}
}