Last active
August 9, 2019 21:27
-
-
Save raghuvarmabh/eccd9e9f1221fe4501c8f2c8d8da55dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static String getNextAvailableTicket() { | |
String availableNumber = null; | |
try { | |
synchronized(TicketingSystem.class){ | |
for (Ticket number: numberList) { | |
if(number.getStatus() == "open") { | |
number.setStatus("pending"); // changing the state of the object | |
System.out.printf("Thread name %s - number found %s \n",Thread.currentThread().getName(), number.getName()); | |
Thread.sleep(5000); // assume processing some business logic | |
number.setStatus("open"); // decide to put it back due to some error | |
availableNumber = number.getName(); | |
break; | |
} | |
} | |
} | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment