Java Thread A is attached to an object
B, which is responsible for writing data
toAfile. After writing data, ThreadAcalls
the following method in object B, where
it waits until more data is available.
private void synchronized waitForData()
{ // (1)
try { // (2)
wait(); // (3)
} catch (InterruptedException ex) { // (4)
}}
Another Thread, executingAmethod in
another object C, needs to wake up
Thread A. Assuming that object C has
references to bothAand B, select all of
the following code fragments that
would cause ThreadAto exit the
wait ForData method.
Answers
Answered by
0
Answer:
// Java program to illustrate need
// of Synchronization
import java.io.*;
class Multithread
{
private int i = 0;
public void increment()
{
i++;
}
public int getValue()
{
return i;
}
}
class GfG
{
public static void main (String[] args)
{
Multithread t = new Multithread();
t.increment();
System.out.println(t.getValue());
}
}
Output:
1
Similar questions