Is a BlockingQueue appropriate? What action should be taken if the Queue is empty? It sounds like you probably have a limited number of connections to your third party software. In that case, you might want to display an explanatory message to any user who cannot obtain a user ID. In that case, blocking wouldn't be useful. You could just implement some synchronization around a standard Queue and handle empty Queues as you see fit. Something like this?
public class UserIDQueue {
private static final Queue<String> USER_IDS = loadUserIDs();
private static final Object USER_ID_LOCK = new Object();
//doesn't need to be synchronized as it is called at class load time
private static Queue<String> loadUserIDs() {
Queue<String> userIDs = new LinkedList<String>();
for(String userID : THIRD_PARTY_USER_IDS) {
userIDs.add(userID);
}
return userIDs;
}
public static String getNextUserID() {
synchronized(USER_ID_LOCK) {
String userID = USER_IDS.poll();
if (userID == null) {
//not sure what your logic is, probably an exception
}
return userID;
}
}
public static void returnUserID(String userID) {
synchronized(USER_ID_LOCK) {
USER_IDS.add(userID);
}
}
}