Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
42 lines (42 loc) · 997 Bytes

File metadata and controls

42 lines (42 loc) · 997 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
36
37
38
39
40
41
42
package chapter18;
/* J18_09.java */
/* Using stop() and yield() Thread Control Methods */
class A extends Thread // Thread A
{
public void run()
{
for(int i= 1; i<=5; i++)
{
System.out.println("Inside Thread A : i = " +i);
if(i%2==0)
yield();
}
System.out.println("Exit From A.");
}
}
class B extends Thread // Thread B
{
public void run()
{
for(int j= 2; j<=6; j=j+2)
{
System.out.println("Inside Thread B : j = " +j);
if(j==4)
stop();
}
System.out.println("Exit From B.");
}
}
public class J18_09 // Main Thread
{
public static void main(String args[])
{
A Th1 = new A(); //Creating Object of Thread A
B Th2 = new B(); //Creating Object of Thread B
System.out.println("Starting Thread A:");
Th1.start(); // Calls run() Method of Thread A
System.out.println("Starting Thread B:");
Th2.start(); // Calls run() Method of Thread B
System.out.println("Exit From Main Thread.");
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.