Weird GWT issue causing IE threads to skyrocket.

Posted by WesleyJohnson on Stack Overflow See other posts from Stack Overflow or by WesleyJohnson
Published on 2010-06-11T19:53:16Z Indexed on 2010/06/11 20:42 UTC
Read the original article Hit count: 151

Filed under:
|
|
|

I'm not sure if this is an issue with GWT, JavaScript, Java, IE or just poor programming, but I'll try to explain. We're implementing web based chat program at work and some of our users have unreliable connections. So we're running into issues where they send out a new message and after x number of milliseconds have passed, the XHR request timesout and the client tries to resend the message again. The issue we ran into was sometimes the message would make it to the server and into the DB, but the XHR request wouldn't make it back to the client so the client was essentially retrying requests that had alread made it to the server. To mitigate this issue, we now send along a count/key with the message. The client says, hey I'm sending msg 50 and it's text is this. If the server already has that message, it just sends back "ok, I got it" and doens't insert into the DB again, eliminating dupes. So the client is free to keep retrying over and over until finally a call comes back from the server saying "Ok, I got it" and then it increments the key and moves on (or we keep them out of the chat if it fails enough). Anyway, so that's the background of what we're doing. The issue is, when we add this code on some versions of IE the threads start increasing gradually everytime it's accessed.

On IE8 for Windows7 x64 it doesn't really seem to do it, but on IE8 for Windows Vista x86 it does. So I can't really pinpoint if it's a fluke or my code. Maybe someone had some ideas on a better way to do this. Here is some pseudo code: (the issue seems appear where I increment messageCount? Is this a scope thing, naming conflict, maybe the issue is entirely somewhere else and I'm way off base.

public class SFChatClient implements EntryPoint
{
    private List<String> messageQueue;
    private Integer messageCount = 0;

    public void onModuleLoad()
    {
        messageQueue = new ArrayList<String>();
        // setup ui and what not
        // add a keyhandler to an input box that checks for <ENTER> and calls sendMEssage()
    }

    private void sendMessage()
    {
        // add message content to the UI for the chat
        messageQueue.add( //get message from user );
        sendQueuedMessages();
    }

    private void sendQueuedMessages()
    {
        if( messageQueue.size() > 0 )
        {
            String outgoingMessage = messageQueue.get( 0 );
            WebServiceClass.sendMessage( outgoingMessage, messageCount, new WebServiceHandler()
                {
                    public void onSuccess()
                    {
                        // Delete item 0 from messageQueue
                        messageCount = messageCount + 1; // <--- this seems to cause IE to leak threads. Taking out this code stops the issue???
                        sendQueuedMessages();
                    }

                    public void onError()
                    {
                        // Do error handling
                        sendQueuedMessages();
                    }
                }
            );
        }
    }
}

public class WebServiceClass()
{
    public void sendMessage( String message, Integer messageCount, handler )
    {
        RequestBuilder builder = new RequestBuilder(// create request builder with proper params for the web service url, JSON content type, etc )
        {
            public void onSuccess()
            {
                handler.onSuccess()
            }

            public void onError() 
            {
                handler.onError()
            }
        }

        builder.setData( // JSON with message );
        bulder.send();
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about JavaScript