Best approach to updating JTable rapidly

Posted on 2011-10-11
Last Modified: 2012-05-12
I've been having a problem with my program getting bogged down when many updates happen at once.  

I have a table model that has a method in it

I've tried calling this many different ways.

I have a thread receiving new data objects which stores them in a buffer, then I process the buffer in another thread, which basically gets an object from the buffer and calls updateTable in the table model with the object from the buffer.

The updateTable method takes the  data and calls setValueAt(.......)

I've tried using a swingWorker for each call to the updateTable method in the processing thread.

Everything seems to work, until I get a hundred updates at once, then things come to a crawl.

It would make sense if I thought I was creating a hundred worker threads when I get the hundred updates, but I've read the swing worker uses a pool of 10 threads as a default.

I tried creating my own thread pool of 5 threads, which worked however it ran even slower.

Maybe I'm not supposed to be calling setValueAt in the model?

This is all part of a bigger program so I don't have stand alone code that runs which I can post, but I can make one tomorrow if the information I've given is not enough information.
Question by:dev110
    LVL 47

    Accepted Solution


    check this article dealing with tihuis issue of many updates to JTable
    LVL 86

    Expert Comment

    >> but I can make one tomorrow if the information I've given is not enough information.

    That might be useful - for you AND us
    LVL 10

    Expert Comment

    If your TableModel extends DefaultTableModel (AbstractTM?) I think the setValueAt() method will fire events to update the JTable's UI, meaning every update you make triggers a re-render which is likely what is bogging your code down.  You are probably better off changing the underlying data structure in bulk (without using the setValueAt() method) and then calling the appropriate fireTableXxx() event handler to notify the table your data has been updated.
    LVL 47

    Expert Comment

    Read that link about Christams tree above - it has all that advice about accumulating changes and much more about dealing with the tables which undergo fast changes

    Author Comment

    I was having trouble duplicating the problem with a stand alone program extraced from
    my actual program, which is actually a plugin to another software.

    I did end up finding the culprit of my CPU usage, which turned out to be a loop that was comparing against the size of the table. I've reworked that loop with use of some hashmaps
    and all is much faster now.

    I've read  the link about the Christmas tree and implemented  some of the techniques referenced in the link. I was able to lower the CPU usage a little bit more.

    Thanks for  all of  your responses,  I know I didn't give much to go on without posting any code.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    Title # Comments Views Activity
    copyEvens challenge 6 46
    strDist challenge 35 69
    wordmultiple challenge 12 62
    Starting to learn JAVA, 7 34
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now