I have to design a mini database server. Machine that has the database will be called server, and the machine that sends request to it will be client. When the server machine boots, a server socket is opened on the machine to listen to client requests for the database. The server.java class has the main method that opens the server socket. The main method then spawns threads for read and write operations. The database server application is so designed that when there is no or only read operation(s) going on on a file(flat file database), allow further read operations and if a write request is made this write thread must wait till all the read threads exit. Similarly if a write operation is going on, any other read or write request thread must wait. A single client request may spawn multiple read, write threads on various files. Multiple clients may make simultaneous requests to the server. The problem is that, whenever a client has a blocked read or write thread, the next calling client is not granted a network connection to the database, i.e. the accept() method does not get called. This happens only because the control is not going back to the main thread. Whenever a thread has to wait, I make it sleep. This must automatically yield control to the main thread and let other clients connect. But it does not happen. In fact, if I have a client that has all read operations, and hence no thread is blocked, the next calling clients are accepted. But as soon as even a single thread of any one client has to wait, no next client is accepted. Although when the waiting thread gets the control in due time, the next client is connected.
I tried the same program for a test program where the main thread does not make network connections but runs a loop to print 50 numbers. In this case the main thread does resume control when a child thread gets blocked.