Hello.
I don’t know what to do anymore so I’m hoping this happened before and someone knows the solution.
I noticed that my game client freezes about every 10th time it connects to server. I’m calling connect method directly from main menu in main thread so when this occurs repaints don’t work and minimize / restore gives emtpy gray screen. I must stop the jvm to shutdown the game. Soon I discovered on what line thing freezes… when connecting to server it uses SocketChannel.open(IP), sets blocking on channel to false, and finally registers for OP_READ. Game froze on:
s_channel.register(selector, SelectionKey.OP_READ);
… I was thiniking maybe it’s some synchronization problem since I have main menu thread, animation thread, server thread and packet sender thread. Allthough they didn’t touch much, especially here, I deceided to synchronize it on selector:
System.out.println("BBBBBBBBBBBBB");
synchronized (selector) {
System.out.println("CCCCCCCCCCCC");
try {
s_channel.register(selector, SelectionKey.OP_READ);
System.out.println("DDDDDDDDDD");
...........................and so on............................
On my suprise the thing kept freezing as before, but the suprising part is that now it froze on
synchronized (selector) {
line! Like wtf!? The B’s are printed out, but the C’s are not… I’m feeling really dumb now, could this be something completely different? Why would it freeze on java keyword? Only thing in common in both freezes is selector reference.
Anyway I’m hoping I’m assuming it wrong and then it could be something else since I don’t know how to fix this. Any similar experience? Any suggestions on ways how to debug this? Thank you.
Edit: forgot to explicitly mention, it does not throw an exception or native error, it just freezes in a way you can minimize / maximize it (gray screen) but all other things like clicks and others are gone as I can see.
), it dosen’t have anything about select() locking selector or I missed / ignored it. Actually I’m not so suprised as it uses lock on selector now, but I was suprised it worked in 90% of time so I didn’t bother to think of it that way. If it won’t work at all (as expected with this) then I would find it.