×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    7

    MIDLet running very slow on Nokia Phones.

    hi all,

    Im stuck with this problem for days. I am developing an application that quotes stock values in J2ME, its quite simple, just show some text in the screen. I am using a socket connection in separated threads to receive the data and it runs fine in almost every test phone I have. When I try to run it in my N95 however, the application becomes ridiculously slow, each command takes like 15 seconds to process, and I have no idea why it only happens in Nokia devices.

    Does anyone know what can be wrong with it? Thanks.

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: MIDLet running very slow on Nokia Phones.

    Are you calling:

    Code:
    System.gc();
    If you are, remove it. It's unnecessary, and is notoriously slow on Series 60.

    Graham.

  3. #3
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: MIDLet running very slow on Nokia Phones.

    Also, if you are using InputStream and it's methods for handling the data, there are Known Issues such as this one:

    KIJ000806 - Using InputStream.skip() in S60 devices slows down MIDlet execution

    More in depth about InputStream in this Forum Nokia Wiki article:

    Reading an InputStream in Java ME

    Regards,
    r2j7
    [URL="http://library.forum.nokia.com/java"][B] >>> Java Developer's Library <<<[/B][/URL]
    [URL="https://www.developer.nokia.com/Resources/Support/Technical_support.xhtml"] [B]>>> Technical Support for Java ME development <<<[/B][/URL]
    [URL="https://publish.ovi.com/info/"][B]>>> Nokia Publish: reach millions of Nokia users worldwide through Nokia Store <<<[/B][/URL]

  4. #4
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: MIDLet running very slow on Nokia Phones.

    Hi ,

    My finding as developer is if you are writing the huge data into the rms and if you keep opening and closing the record store and the application is installed in the memory card I have seen the slowness.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    7

    Unhappy Re: MIDLet running very slow on Nokia Phones.

    hi,

    thanks for the replies, but the problem persists.

    Yes, I was using System.gc(), I removed it but it is still very slow. I've tried all the methods to receive inputstream too, I've even disabled it, but didn't solve, and I'm not writing into the rms and it is installed in the phone memory. Any other idea?

  6. #6
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: MIDLet running very slow on Nokia Phones.

    I am using a socket connection in separated threads to receive the data
    Could you try f.ex. to reduce the number threads to see if that results in improvement in application performance? (I.e., whether the performance is better when there is less threads running at the same time?)

    Regards,
    r2j7
    [URL="http://library.forum.nokia.com/java"][B] >>> Java Developer's Library <<<[/B][/URL]
    [URL="https://www.developer.nokia.com/Resources/Support/Technical_support.xhtml"] [B]>>> Technical Support for Java ME development <<<[/B][/URL]
    [URL="https://publish.ovi.com/info/"][B]>>> Nokia Publish: reach millions of Nokia users worldwide through Nokia Store <<<[/B][/URL]

  7. #7
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: MIDLet running very slow on Nokia Phones.

    Try to monitor the heap memory utilization on the device and see if you are not forcing the device VM to run Garbage collector again and again. Re-use Objects, Control your max heap use to 75% of the available and you will see that it performs better.

    thanks,
    Ekta

  8. #8
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: MIDLet running very slow on Nokia Phones.

    well that might be difficult, he is using a N95, which has a variable (dinamic) heap...
    personally I would also use on-device debugging (possible with a N95) to see it's memory usage behaviour, and also on the emulator just to see if there is some kind of correlation between the two...

  9. #9
    Registered User
    Join Date
    Apr 2009
    Posts
    7

    Re: MIDLet running very slow on Nokia Phones.

    Quote Originally Posted by Tiger79 View Post
    well that might be difficult, he is using a N95, which has a variable (dinamic) heap...
    personally I would also use on-device debugging (possible with a N95) to see it's memory usage behaviour, and also on the emulator just to see if there is some kind of correlation between the two...
    well, I'll try to monitor it and see what is happening. However it's quite strange, because the app runs fine in lower phones, like Sony Ericsson w580i, and many others. The problem seems to occur only in Symbian based systems.

  10. #10
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: MIDLet running very slow on Nokia Phones.

    Is you application based on some UI library like J2me Polish, LWUIT or any other which is optimized for J2me on Java phones and not smartphones?
    Thanks,
    Ekta

  11. #11
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: MIDLet running very slow on Nokia Phones.

    SE use specific graphics buffers (for images for exmaple) which might speed up the apps on their platforms considerably, but this is only the case when for example a lot of Images are used...

  12. #12
    Registered User
    Join Date
    Apr 2009
    Posts
    7

    Re: MIDLet running very slow on Nokia Phones.

    Quote Originally Posted by ektasrv View Post
    Is you application based on some UI library like J2me Polish, LWUIT or any other which is optimized for J2me on Java phones and not smartphones?
    No, i made the UI by myself.

    Quote Originally Posted by Tiger79 View Post
    SE use specific graphics buffers (for images for exmaple) which might speed up the apps on their platforms considerably, but this is only the case when for example a lot of Images are used...
    Yes, the program use some images but I dont think this is the case. Actually I found out that the app runs "almost" normal in the app's main menu, that has some icons. The slowdown begins when the phone is exchanging data with the server, so I think the problem is somehow related to the sockets or to the threads used.

  13. #13
    Registered User
    Join Date
    Apr 2009
    Posts
    7

    Re: MIDLet running very slow on Nokia Phones.

    Maybe I forgot to mention, but I am using Netbeans with the Java(TM) Platform Micro Edition SDK 3.0 and installing the generated jar file directly. Do I need to use any Nokia specific SDK or tool? Thanks.

  14. #14
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: MIDLet running very slow on Nokia Phones.

    Quote Originally Posted by efmiglioranza View Post
    Maybe I forgot to mention, but I am using Netbeans with the Java(TM) Platform Micro Edition SDK 3.0 and installing the generated jar file directly. Do I need to use any Nokia specific SDK or tool? Thanks.
    That's enough to use and to develop the application of most of the types.

    [QUOTE=efmiglioranza;
    Actually I found out that the app runs "almost" normal in the app's main menu, that has some icons. The slowdown begins when the phone is exchanging data with the server, so I think the problem is somehow related to the sockets or to the threads used[/QUOTE]

    Is the class for the main menu separate from the other?
    Are you using the thread in the main menu class and are you sure that as soon as you quit from the main menu and moving towards the other module of the app you are closing the main Menu thread?

    How your connection and the server classes structure is?
    Last edited by raj_J2ME; 2010-06-09 at 05:00.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  15. #15
    Registered User
    Join Date
    Apr 2009
    Posts
    7

    Unhappy Re: MIDLet running very slow on Nokia Phones.

    There are basicaly two threads, one to handle the UI and user input with the actual canvas and another one to receive and translate incoming messages. So, when I move towards in the program, it just changes the actual canvas to the new one in the main thread. For the connection classes I've tried two ways:

    This is the connection thread loop:
    Code:
    public synchronized void run() {
    
        	while (true) {
    
                // Process received data
                try {
                    Message m = inputStream.read();
                    if (!UserData.getInstance().isLogged()) {
                        m.processOffline();
                    } else {
                        m.processOnline();
                    }
                }
    
                // Connection lost
                catch (ConnectionTimeoutException e) {
                    handleErrors(e);
                }
    
                catch (Exception e) {
                    e.printStackTrace();
                }
            }
     
        }
    Where inputStream is a MessageInputStream, a wrap over the InputStream, here is the read method that returns a Message:

    Code:
        public Mensagem read() throws ConnectionTimeoutException, IOException {
    	// Checks for a complete message in the buffer
            while(!hasMessage()){
                loadBufferWithData(in);
            }
    
    	Message m = Message.createMessage(MsgID(buffer));
            int packetSize = getPacketSize() + 1;
    
            // Copy the message buffer
            byte[] messageBuffer = new byte[packetSize];
            System.arraycopy(buffer, 0, messageBuffer, 0, packetSize);
            
            m.setBuffer(messageBuffer);
            removeMessageFromBuffer(packetSize);
    
            return m;
        }
    And here the loadBufferWithData that pools for incoming data (first way):

    Code:
        public void loadBufferWithData(InputStream inputData) throws ConnectionTimeoutException, IOException {
            synchronized(this) {
                           
                byte[] arBuffer;
                
                waitForPacket(inputData);
                int bytesRead = inputData.read(arBuffer = new byte[inputData.available()+getBuffer().length], getBuffer().length, inputData.available());
                System.arraycopy(getBuffer(), 0, arBuffer, 0, getBuffer().length);
                setBuffer(arBuffer);
            }
        }
    This first option is using a busy wait, I dont like this but it was already there when I got the code:

    Code:
        public void waitForPacket(InputStream inputData) throws ConnectionTimeoutException, IOException {
    
            long startTime = System.currentTimeMillis();
            
            while(inputData.available() == 0) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException ex) {
    
                }
    
                checkTimeout(startTime);
            }       
        }
    The code above works, but I think it's kinda crap (as I said, I got the project running). However, the N95 was still receiving some quotes, but very very slowly. Then I tried to refactor it to this (second way):

    Code:
        public void loadBufferWithData(InputStream inputData) throws ConnectionTimeoutException, IOException {
            synchronized(this) {
    
                byte[] arBuffer;
    
                long startTime = System.currentTimeMillis();
                
                byte[] newData = new byte[1500];
                int bytesRead = inputData.read(newData);
    
                if (bytesRead <= 0) {
                    checkTimeout(getLastTimeRecData());               
                } else {
                    arBuffer = new byte[getBuffer().length + bytesRead];
    
                    System.arraycopy(getBuffer(), 0, arBuffer, 0, getBuffer().length);
                    System.arraycopy(newData, 0, arBuffer, getBuffer().length, bytesRead);
                    setBuffer(arBuffer);
    
                    setLastTimeRecData(System.currentTimeMillis());
                }
            }
        }
    Ok, not a perfect one but it worked a lot better in other phones. In the N95 however, the app even stoped to receive some quotes, being slowly the same way it was before, but now without any data received. I even tried to change the thread's run loop to do nothing, dont handle any message but the UI (besides the main menu) is still very slow.

Similar Threads

  1. Nokia 7650 support Bluetooth audo?
    By ovjo12 in forum Bluetooth Technology
    Replies: 5
    Last Post: 2003-07-17, 18:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×