I'm really surprised that locking collection with an empty block is not removed at compile time. Pretty cool that it works. I mean that it works, it is proactive, this is not the most beautiful approach, but it works. This is better than a dream, because it is predictable, and since you use awakening, you know that progress will be made as necessary, and not with periodic updates, if you simply rely on the timeout of choice.
The main disadvantage of this approach is that you say that calls register the trump card of everything else, even serving requests. What may be true in your system, but usually it is not, I would say that this is a possible problem. A small problem, which is more promising thinking, is that you are blocking SelectorThread itself, which in this case is a larger object. Not bad, it doesn't matter, although when you expand, this castle will simply document and take into account when other clients use this class. Personally, I would like to make another castle to avoid any unforeseen future dangers.
Personally, I like queuing methods. They assign roles to your threads, such as the master and workers. While all types of control occur on the host computer, for example, after each selection check for more registrations from the queue, clear and process any reading tasks, process any changes in the general connection settings (disconnects, etc.) ... The "bs" <Model w390> seems to fit quite well with this model, and it is a pretty standard model. I don’t think this is bad, because it makes the code a little less cracked, more verifiable and easier to read imo. It just takes more time to write out.
Although I admit that a lot of time has passed since I last wrote this material, there are other libraries that take care of the queue for you.
The Grizzly Nio Framework , while a bit old, the last time I used it, the main runloop was pretty good. He sets up many queues for you.
Apache Mina Similarly, it provides a queue structure.
But I mean, in the end, it depends on what you are working on.
- Is this a project for one person who just needs to work with a wireframe?
- Is this a piece of code that you want to live for years?
- Is this a piece of production code that you are repeating?
If you do not plan to use this as the main part of the service you provide to clients, I would say that your approach is in order. This may ultimately have a maintenance problem.