Skip to content

Instantly share code, notes, and snippets.

@brendoncheung
Last active August 12, 2019 19:19
Show Gist options
  • Save brendoncheung/f942bf0b1b1e8a6ef033c3d76e558ef6 to your computer and use it in GitHub Desktop.
Save brendoncheung/f942bf0b1b1e8a6ef033c3d76e558ef6 to your computer and use it in GitHub Desktop.
class TicketManager {
private int mNumberOfTickets = 100;
void purchaseTickets(int amount) {
someTimeIntensiveTask();
if (mNumberOfTickets >= amount) {
mNumberOfTickets = mNumberOfTickets - amount;
} else {
// Tickets all sold!
}
}
private void someTimeIntensiveTask() {
try {
Thread.currentThread().sleep(1000);
System.out.println(Thread.currentThread().getName() + " is making connection to database.........");
} catch (Exception e) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment