Two Synchronization Methods
import java.io.*;
class Account
{
private double balance;
Public Account(double initialDeposit)
{
balance = initialDeposit;
}
public
synchronized double getBalance()
{
return balance;
}
public
synchronized viod deposit(double amount)
{
balance += amont;
}
}
public static void abs(int[] values)
{
synchronized (values)
{
for (int i = 0; i < values.length; i++)
{
if (values[i] < 0)
values[i] = -values[i];
}
}
}
No comments:
Post a Comment