YaroslavGaponov / StompLib

STOMP client library for Java
12 stars 4 forks source link

high CPU occupation when notice server stop #5

Open conanca opened 11 years ago

conanca commented 11 years ago

I have a java app, the client always keep a stomp connection in it; When notice server stop, the process of this java app will be in high CPU occupation,but stomp client didn't hava any error print out.

YaroslavGaponov commented 11 years ago

try now

conanca commented 11 years ago

fixed

conanca commented 11 years ago

when activeMQ server is Linux, this problem will still happen.

I try to fix it like this: class StompClient Line 142:

                do {
                    ch = in.read();
                    if(ch<0){
                        onCriticalError(new IOException("stome server disconnected!"));
                        return;
                    }
                } while (ch < 'A' || ch > 'Z');
redcrab2016 commented 6 years ago

By @conanca comment (0ct 19,2012) context : Linux with activeMQ still have SocketException at line class StompClient Line 144 (ch=in.read()) when executing the test class => Exception occurs when client.disconnect(); is invoked in test class. (Line 130) then I fixed it by modifying StompClient Line 142 as

        // skip lead trash
        do { 
            try {
                ch = in.read();
            } catch (SocketException e) {
                if (!running) { // exception to ignore
                    break;
                } else {
                    throw e;// normal exception
                }
            }
            if (ch < 0){
                            onCriticalError(new IOException("stome server disconnected!"));
                            return;
            }
        } while (ch < 'A' || ch > 'Z');
        if (!running) break;
        // read frame
        (...)

=> ignore exception when SocketException is thrown at in.read() and the reader should be stopped (running == false)