samedi 4 mai 2019

Making an action when list reaches a certain ammount

I have a thread that adds connections to a list. My application needs to do pick 2 random elements when the list gets bigger then two elements.

After that the program does some actions on the connections and then removes the two connections out of the list.

I already tried to make a separate thread run and check if the list is bigger then 2 elements.

When its bigger it picks 2 random elements out of the list and does the action with them, and then removes them from the list.

Is there a better way to do this in a design pattern way? I don't think that running another thread that keeps checking if list is bigger then 2 is a good solution.

Aucun commentaire:

Enregistrer un commentaire