I'd try to implement something like this:
You'll need one list or collecting holding all clients being connected. You'll need random access, i.e. you'll have to add clients to the front or back and you'll have to be able to remove any element at any time. Bonus points if the list is sorted by number of assigned records (ascending).
When there's a new record to process (or while you iterate over a list with them):
- Send the record to the client being in front of your list.
- Remove the client from the front of the list and add it to the back (unless the list is sorted anyway).
- When a new client connects, it's added to the front of your list.
If a client disconnects, it's removed from the list and the records are readded for redistribution.
If I didn't make any mistake while thinking about this, this should ensure that always one of the clients with the least number of tasks will get a new record unless many clients drop mid-processing. In that case a sorted list would be an advantage.
Of course, there's room for optimization and it's not the best strategy if your number of clients doesn't change while processing (and only before you start doing so). In this case you could simply determine the client that's supposed to process record n using i = n % number_of_clients.
http://stackoverflow.com/questions/21829187/how-to-distribute-collection-of-values-to-dynamic-list[
^]