public void fix(Account from, Account to, int money) throws InterruptedException { if (from.hashCode() > to.hashCode()) { synchronized (from) { Thread.sleep(2 * 1000L); System.out.println("get from" + from.getName() + ",waiting " + to.getName()); synchronized (to) { decreaseAccount(from, to, money); } } } else if (to.hashCode() > from.hashCode()) { synchronized (to) { Thread.sleep(2 * 1000L); System.out.println("get from" + from.getName() + ",waiting " + to.getName()); synchronized (from) { decreaseAccount(from, to, money); } } } else { synchronized (xLock) { synchronized (to) { synchronized (from) { decreaseAccount(from, to, money); } } } } }
@Override public int hashCode() { int result = account != null ? account.hashCode() : 0; result = 31 * result + (plan != null ? plan.hashCode() : 0); result = 31 * result + (uuid != null ? uuid.hashCode() : 0); // result = 31 * result + (state != null ? state.hashCode() : 0); result = 31 * result + (unitAmountInCents != null ? unitAmountInCents.hashCode() : 0); result = 31 * result + (currency != null ? currency.hashCode() : 0); result = 31 * result + (quantity != null ? quantity.hashCode() : 0); result = 31 * result + (activatedAt != null ? activatedAt.hashCode() : 0); result = 31 * result + (canceledAt != null ? canceledAt.hashCode() : 0); result = 31 * result + (expiresAt != null ? expiresAt.hashCode() : 0); result = 31 * result + (currentPeriodStartedAt != null ? currentPeriodStartedAt.hashCode() : 0); result = 31 * result + (currentPeriodEndsAt != null ? currentPeriodEndsAt.hashCode() : 0); result = 31 * result + (trialStartedAt != null ? trialStartedAt.hashCode() : 0); result = 31 * result + (trialEndsAt != null ? trialEndsAt.hashCode() : 0); result = 31 * result + (addOns != null ? addOns.hashCode() : 0); return result; }
@Override public int hashCode() { return account != null ? account.hashCode() : 0; }