-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyieldDemo.java
More file actions
35 lines (31 loc) · 807 Bytes
/
Copy pathyieldDemo.java
File metadata and controls
35 lines (31 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Java program to illustrate yield() method
// in Java
import java.lang.*;
// MyThread extending Thread
class MyThread extends Thread
{
public void run()
{
for (int i=0; i<5 ; i++)
System.out.println(Thread.currentThread().getName()
+ " in control");
}
}
// Driver Class
public class yieldDemo
{
public static void main(String[]args)
{
MyThread t = new MyThread();
t.start();
for (int i=0; i<5; i++)
{
// Control passes to child thread
Thread.yield();
// After execution of child Thread
// main thread takes over
System.out.println(Thread.currentThread().getName()
+ " in control");
}
}
}