Timer won't execute untill daemon thread yields
In short I'm finding that a daemon thread appears to be preventing a timer from another thread from running until it completes it's startup process. But to give more detail...
I have a client application with a main class that has only the constructor and synchronized connect/disconnect methods. The constructor starts a timer which sends a heartbeat to my server once every second. I found my server is killing the client every time I connect because it's not receiving the heartbeat soon enough and thus assuming the server is dead/frozen.
I traced the problem to another thread started by my main threads connect method. If this thread isn't started there is no problem, when this thread starts everything is delayed.
After further testing I discovered that heartbeat messages will work fine until a connection, then the daemon thread would start running and no heartbeat messages are sent until the daemon thread finishes it's first iteration and calls sleep (it's an infinite loop that sleeps between polling). Once the daemon thread yields I see two heartbeats immediately sent, as if they were queued and waiting to be sent. The entire process takes about 2 seconds.
So why does a daemon thread prevent my timer from running? I would think that after a second the JVM would interrupt the daemon thread long enough for the timer to run, wouldn't it? Is it possible to set the timer thread as a higher priority so it is guaranteed to interrupt other threads at least once a second?