Multiple java threads and blocking in native code
843829Jul 8 2004 — edited Jul 12 2004I have created two Java thread that use JNI to call two native methods, receiveMessage and receiveImage. One thread calls receiveMessage exculsively and the other calls receiveImage exclusively. Since there is no intersecting data, neither of the methods are synchronized. Both of the receive methods call navite methods that block untill there is data to return.
Now from what I understand, once one of the threads block, it should give up the cpu and let other threads (including the main thread) run. For one instance, what actually happens is the whole java process is blocked. When the receiveImage is called and there is no image ready (another native program is reading it from disk and getting ready to send it to the native method that receives it using a communication network handled by a non-windows OS), both the user-created Java threads block (stop calling methods) AND the java main thread stops running (the gui does not repaint and does not respond to user input) until the receiveImage method call returns. After it returns everythings starts running again.
There is not always going to be images or messages waiting to be received by the java threads, this will be the normal behavior, so it will be common for the java threads to block for some time. The problem is that the thread that draws the gui and response to user input is not running.
Do I just have the wrong understanding of threads or is there something more going on. Has anyone else had this problem or knows a solution? The java and the methods being called by the java are running off of win NT but the native methods sending the data are running on a different processor using a different OS. The producer-consumer communication is using a library supplied by the other OS.