chandlerethan 26 Share 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. Link to comment Share on other sites More sharing options...
Banker 175 Author Share 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 Link to comment Share on other sites More sharing options...
chandlerethan 26 Share 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 Link to comment Share on other sites More sharing options...
Dreamlicker 750 Share 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.