So, it's amazing what reading two 600 page books can do. So in the two days of coding (from scratch)...
The server will sit and listen for connections. (two objects, (A) one thread to listen for incoming requests and when it gets one it takes the connection and puts it in a pool for (B) the request processor. The request processor will be made of 25 threads to process incoming requests, so they'll all be watching the pool, waiting.
The (A)Thread will then say "Yoh you have work" (updateAll()). Like swarms, the first to get to the request freezes the pool (synchronize(pool)) and handles the connection by popping it out of the pool so no one else can get to it. It then let's go of the pool.
Since the request processor threads (B) are all going to need to talk to the database (I already have it connecting to the DB and getting a record), and since I want to save resources they are all going to share one database connection. Since that B-Thread that just got to the request is going to be using the database connection, they'll all have to wait (synchronize(dbConn)) if there's work to be done requiring the db.
The console knows about the AlertObject, and it prefilled it with the question "Hey you got any alerts for me?". Since the b-thread knows the what "common object" (alert object) looks like. It will read the information coming from the console straight into its version of the AlertObject. Now the (B)Thread has its own copy, it'll tell the AlertObject what the "shared" database connection is, and tell the AlertObject "find out for yourself".
The alertobject is going to fill itself up (with alerts) by contacting the database and return to the (B)thread that called it. The (B)Thread is going to go, OK, you don't need the dbconnection so let me allow the other 24 (B)threads to use the database connection.
Since the (B)Thread knows that the console knows what the AlertObject looks like - the console just sent him an empty one - it's going to stream the alertobject back to the console... who, by the way, is still waiting for a response.
That thread is then going to go back to the pool to check for more connections that the A-Thread may have dropped off.... but alas, some other B-thread got there first, so he'll just have to wait.
Phew... I LOVE CODING!
