Skip to content

Instantly share code, notes, and snippets.

@tonussi
Created June 23, 2013 17:25
Show Gist options
  • Save tonussi/5845789 to your computer and use it in GitHub Desktop.
Save tonussi/5845789 to your computer and use it in GitHub Desktop.
Simples classe de conta bancária
package concorrente;
public class Conta {
private int saldo = 0;
public synchronized boolean retira(int montante) {
assert (montante <= 0 || saldo < montante) : "montante: " + montante
+ "saldo: " + saldo;
saldo -= montante;
return true;
}
public synchronized void deposita(int montante) {
assert (montante >= 0) : "montante: " + montante;
saldo = saldo + montante;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment