chandlerethan 26 Posted November 6, 2016 List<String> cmdQueue = new List<String>(); public void onMessage(Message m) { cmdQueue.add(m.getMessage()); } in your loop: if(!cmdQueue.isEmpty()) { if(cmdQueue.get(0) != null) { //extra null check, not really needed. doCommand(cmdQueue.get(0)); //this gets the oldest command (the first sent command)and handles it cmdQueue.remove(0); //this removes the command from the list after it's been handled } } This is in no way the best way to do it, but it's one way to do it.
Banker 175 Author Posted November 16, 2016 List<String> cmdQueue = new List<String>(); public void onMessage(Message m) { cmdQueue.add(m.getMessage()); } in your loop: if(!cmdQueue.isEmpty()) { if(cmdQueue.get(0) != null) { //extra null check, not really needed. doCommand(cmdQueue.get(0)); //this gets the oldest command (the first sent command)and handles it cmdQueue.remove(0); //this removes the command from the list after it's been handled } } This is in no way the best way to do it, but it's one way to do it. Sorry I've only just seen this now. Hmm, looks like it should work quite effectively. Thanks a lot
chandlerethan 26 Posted November 16, 2016 Sorry I've only just seen this now. Hmm, looks like it should work quite effectively. Thanks a lot No problem
Dreamlicker 750 Posted November 17, 2016 If you're still looking for solutions, there is a literal Queue class in Java that does what you would expect. https://docs.oracle.com/javase/8/docs/api/java/util/Queue.html
Recommended Posts
Archived
This topic is now archived and is closed to further replies.