Java performance problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jos? Cardoso

    #1

    Java performance problem

    Hi,

    I have developed a java application that interacts with a database.
    Now i've the folowing problem:

    - I have a list retrieved from the database(about 200 records);
    - for each, i do a Jlabel constructed from an html String;
    - for each JLabel i construct a JPanel e add it to the main panel.

    this works fine, but when there's an inactivity in the application
    (about 30 minutes), the main panel disapear and the application
    freeze. i don't know the reason for that (perhaps a lack of memomy
    ???).The application runs in a PIII 600mhz with 256 mb of ram.

    Somebody can help me???

    Thanks.
  • Nick Pomfret

    #2
    Re: Java performance problem

    Um? I can't think why it would hang for 30 minutes, 200 records doesn't
    sound like much data. I've seen java render HTML JLabel slowly before (but
    not that slowly!).

    Have you tried removing the html, just use plain text in your JLabels?
    Presumably you're using HTML because you want some nice formatting in your
    JLabels..?

    Have you tried adding your Resultset values into a JTable?

    --

    ** http://www.tabletoolkit.com **
    Aggregate a JTable to an arbitrary level to create your own pivot tables


    "Jos? Cardoso" <joscardoso@yah oo.com> wrote in message
    news:7eabb0c0.0 408300237.36c4e ccf@posting.goo gle.com...[color=blue]
    > Hi,
    >
    > I have developed a java application that interacts with a database.
    > Now i've the folowing problem:
    >
    > - I have a list retrieved from the database(about 200 records);
    > - for each, i do a Jlabel constructed from an html String;
    > - for each JLabel i construct a JPanel e add it to the main panel.
    >
    > this works fine, but when there's an inactivity in the application
    > (about 30 minutes), the main panel disapear and the application
    > freeze. i don't know the reason for that (perhaps a lack of memomy
    > ???).The application runs in a PIII 600mhz with 256 mb of ram.
    >
    > Somebody can help me???
    >
    > Thanks.[/color]


    Comment

    • Jos? Cardoso

      #3
      Re: Java performance problem

      > Um? I can't think why it would hang for 30 minutes, 200 records doesn't[color=blue]
      > sound like much data. I've seen java render HTML JLabel slowly before (but
      > not that slowly!).
      >
      > Have you tried removing the html, just use plain text in your JLabels?
      > Presumably you're using HTML because you want some nice formatting in your
      > JLabels..?
      >
      > Have you tried adding your Resultset values into a JTable?[/color]

      No, i need to show a lot of information for each row, thats why i choose html.

      My program is something like that.

      public class1{

      public class1(){
      ...
      }

      public list1(){
      // creates a JButton for each row
      // each button listner creates a 2nd object -> class2 c2 = new class2()
      c2.list2();
      }

      }

      public class2{

      public class2(){
      ...
      }

      public list2(){
      // creates a JLabel for each row
      }
      }

      I was seeing my taskmanager, and my memory goes to the 40.000 kb for javaw.exe,
      when i run the program and enter in list2.

      Then every time that i call list2, memory for javaw starts goes up to 80.000kb.

      It seems like he isn't releasing the memory for objects created.

      Comment

      • javalpha

        #4
        Re: Java performance problem

        joscardoso@yaho o.com (Jos? Cardoso) wrote in message news:<7eabb0c0. 0408300237.36c4 eccf@posting.go ogle.com>...[color=blue]
        > Hi,
        >
        > I have developed a java application that interacts with a database.
        > Now i've the folowing problem:
        >
        > - I have a list retrieved from the database(about 200 records);
        > - for each, i do a Jlabel constructed from an html String;
        > - for each JLabel i construct a JPanel e add it to the main panel.
        >
        > this works fine, but when there's an inactivity in the application
        > (about 30 minutes), the main panel disapear and the application
        > freeze. i don't know the reason for that (perhaps a lack of memomy
        > ???).The application runs in a PIII 600mhz with 256 mb of ram.
        >
        > Somebody can help me???
        >
        > Thanks.[/color]

        Hi,
        Perhaps you are doing the list retrieval and JLabel creation right
        in the Swing thread. That would explain the "freeze". You may want to
        do the list retrieval in a separate thread. The creation of JLabels is
        probably best done in a separate thread as well, though Sun apparently
        recommends that UI components are best created in the Swing thread
        under some situations. Then get the Swing thread to repaint the window
        (using invokeLater(), for example).

        The blog:

        presents an excellent approach to class threading problems with Swing.

        Javalpha.

        Comment

        • Andrew Thompson

          #5
          Re: Java performance problem

          On 30 Aug 2004 11:16:13 -0700, Jos? Cardoso wrote:
          [color=blue]
          > No, i need to show a lot of information for each row, thats why i choose html.[/color]

          have you considered/tried convertint that table to
          a JList? A JList can accept a custom ListCellRendere r,
          and AFAIU, only the items in the visible area are liable
          to get the HTML overhead..

          HTH

          comp.lang.java,
          comp.lang.java. developer,
          comp.lang.java. help

          Please also note that .developer is not a
          valid group* and three groups too many **.

          * <http://www.physci.org/codes/javafaq.jsp#gro ups>
          ** <http://www.physci.org/codes/javafaq.jsp#xpo st>

          Follow-Ups set top c.l.j.help only

          --
          Andrew Thompson
          http://www.PhySci.org/ Open-source software suite
          http://www.PhySci.org/codes/ Web & IT Help
          http://www.1point1C.org/ Science & Technology

          Comment

          • Jos? Cardoso

            #6
            Re: Java performance problem

            > Hi,[color=blue]
            > Perhaps you are doing the list retrieval and JLabel creation right
            > in the Swing thread. That would explain the "freeze". You may want to
            > do the list retrieval in a separate thread. The creation of JLabels is
            > probably best done in a separate thread as well, though Sun apparently
            > recommends that UI components are best created in the Swing thread
            > under some situations. Then get the Swing thread to repaint the window
            > (using invokeLater(), for example).
            >
            > The blog:
            > http://www.clientjava.com/blog/2004/...059428000.html
            > presents an excellent approach to class threading problems with Swing.
            >
            > Javalpha.[/color]


            Hi,
            My problem isn't the retrieval, is after that. Java don't release the
            memory used during the retrieval, and when the user click on the
            button that make the same retrieval, the memory increases and after
            that freezes.

            Comment

            • Jos? Cardoso

              #7
              Re: Java performance problem

              I think my problem is in java allocated memory. It uses memory for the
              objects created and don't release it. I was working in my application
              until he reaches the 80mb of memory, and if i minimize my GUI, the
              memory for my process cames to 11mb. Otherwise the memory keeps
              climbing and hangs the application.

              Is there any way to release the memory or destroy the objects ?

              Comment

              • Andrew Thompson

                #8
                Re: Java performance problem

                On 31 Aug 2004 08:34:13 -0700, Jos? Cardoso wrote:
                [color=blue]
                > I think my problem is in java allocated memory.[/color]

                Have you tried a JList?
                <http://google.com/groups?selm=1rk hi290ye6qx%24.1 bzin0hkbcvhy.dl g%4040tude.net>
                There is no need for there to be any more than
                a 'screenful' of the HTML (for rendering) at any time..

                But, ..by the way, we have not seen an example
                of your code, that might be the problem..

                Cut out the D/B stuff and create an example
                that creates 200 items for rendering using
                dummy strings/HTML.

                For further tips on an example..
                <http://www.physci.org/codes/sscce.jsp>

                Now, it seems you may not have got my earlier
                reply, you are cross-posting to three groups,
                one of which is not valid, *PLEASE* *STOP* *IT*.

                --
                Andrew Thompson
                http://www.PhySci.org/ Open-source software suite
                http://www.PhySci.org/codes/ Web & IT Help
                http://www.1point1C.org/ Science & Technology

                Comment

                • javalpha

                  #9
                  Re: Java performance problem

                  joscardoso@yaho o.com (Jos? Cardoso) wrote in message news:<7eabb0c0. 0408310734.132a ca7a@posting.go ogle.com>...[color=blue]
                  > I think my problem is in java allocated memory. It uses memory for the
                  > objects created and don't release it. I was working in my application
                  > until he reaches the 80mb of memory, and if i minimize my GUI, the
                  > memory for my process cames to 11mb. Otherwise the memory keeps
                  > climbing and hangs the application.
                  >
                  > Is there any way to release the memory or destroy the objects ?[/color]

                  Hi, here are some thoughts on how I would approach your problem.
                  First, try using the "-verbose:gc" option of your JVM, to see whether
                  the GC runs and, if so, whether it is successful in reclaiming memory.
                  You can also experiment with the "-Xmx" option to the JVM to increase
                  the maximum heap size (to say 128 MB) and see whether the allocated
                  memory saturates at some point. (BTW, the command "java -?" will
                  display all standard options available while "java -X" will display
                  non-standard options.)

                  Secondly, consider nulling out object references when you are sure
                  they won't be accessed again. CAUTION: Premature nulling is a bug and
                  may require lots of unit testing to catch via NullPointerExce ptions.

                  Thirdly, consider running the GC under program control using
                  System.gc(). This is not recommended in general because it is best to
                  let the JVM decide when to run the GC. You could perhaps run the GC
                  before each list retrieval. (This is just a thought, I don't know
                  enough about your app to say whether this is a good idea.)

                  Finally, consider using garbage collectors other than the defaut. JDK
                  1.4 includes no less than <a href=
                  "http://www-106.ibm.com/developerworks/java/library/j-jtp11253/">
                  6 separate garbage collectors</a>. Without knowing more about your
                  application, I cannot say whether this will be helpful or which one is
                  a good candidate to try.

                  Comment

                  • Jos? Cardoso

                    #10
                    Re: Java performance problem

                    tks for your tips.

                    after analise my program, i think that i´ve a problem in the
                    structure.

                    My program is something like that

                    public class1{
                    ....
                    public met1(){
                    class2 = new class2();
                    }
                    }

                    public class2{
                    ....
                    public met2(){
                    class3 = new class3();
                    }
                    }

                    public class3{
                    ....
                    public met3(){
                    .....
                    ....
                    button listener
                    class1 = new class1();
                    }
                    }

                    when i execute my program he works fine, but the memory allocated for
                    the process javaw.exe starts climb, he doesn't release the memory
                    taken.

                    A strange thing happens when i minimize my gui with the mouse, now he
                    dealocates the memory take by the process.... i don't understand why.


                    i agree that the structure isn't very good, but i don't see how can i
                    redefine it. The program should do the folowing:

                    - have a panel with a list of buttons(machine names) obtained from a
                    database.
                    - when we press a button, he must show a list of services for the
                    selected machine.
                    - when we choose a service, he must show the material used in that
                    service.
                    - after that we press a button and the program must list again the
                    services(relate d with the original machine selected).

                    All this must be showed in the same panel.

                    This is an appication that runs with a touch screen


                    tks

                    Comment

                    • Andrew Thompson

                      #11
                      Re: Java performance problem

                      On 1 Sep 2004 03:20:55 -0700, Jos? Cardoso wrote:
                      [color=blue]
                      > My program is something like that..[/color]

                      (that doesn't compile.. SSc*C*e)

                      Did you read that link to the SSCCE?

                      And, ..now that you seem to have dropped
                      one of the cross-posted groups, can I
                      also ask you to drop the invalid group
                      'comp.lang.java ' and follow this up on *only*
                      comp.lang.java. help Jos?(?)

                      And please trim your problem down to a
                      self contained compileable example, there
                      are good reasons for preparing one, see..
                      <http://www.physci.org/codes/sscce.jsp>

                      HTH

                      --
                      Andrew Thompson
                      http://www.PhySci.org/ Open-source software suite
                      http://www.PhySci.org/codes/ Web & IT Help
                      http://www.1point1C.org/ Science & Technology

                      Comment

                      • Raymond DeCampo

                        #12
                        Re: Java performance problem

                        Jos? Cardoso wrote:[color=blue]
                        > I think my problem is in java allocated memory. It uses memory for the
                        > objects created and don't release it. I was working in my application
                        > until he reaches the 80mb of memory, and if i minimize my GUI, the
                        > memory for my process cames to 11mb. Otherwise the memory keeps
                        > climbing and hangs the application.
                        >[/color]

                        It sounds like you are using Windows Task manager to determine how much
                        memory you are using. If that is the case, you cannot simply look at
                        the default memory column that task manager presents. That only
                        displays the amount of physical memory used by the process (that is why
                        you see a great reduction when you minimize an application; Windows
                        swaps out its memory). Use the options of task manager to display the
                        virtual memory as well.

                        As an alternative, you can use System.freeMemo ry(), etc. to get the
                        information direct from the JVM.

                        HTH,
                        Ray

                        --
                        XML is the programmer's duct tape.

                        Comment

                        Working...