Created
August 12, 2019 18:49
-
-
Save brendoncheung/2430ca6baf7e5f4f1e04a2d0cd9e20bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TicketManager { | |
private int mNumberOfTickets = 100; | |
synchronized void purchaseTickets(int amount) { | |
if (mNumberOfTickets >= amount) { | |
makingNetworkConnectionToServer(); | |
mNumberOfTickets = mNumberOfTickets - amount; | |
} else { | |
// Tickets all sold! | |
} | |
} | |
private void makingNetworkConnectionToServer() { | |
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