JTextArea brings program to crash?

Discussion in 'Java' started by korcs, Oct 16, 2007.

  1. korcs

    korcs Guest

    Hi,

    I use a JTextArea instance in my app to visualize program outputs.

    I have a LOT of output, and I have experienced, that if I use
    JTextArea instead of TextArea, after a certain time it does not take
    any more appends, so my threads which are trying to use the JTextArea
    to output something are stopping (start waiting for ethernity).

    Does anybody have an idea how could I avoid this? I suppose, that one
    could check after or before each append the size of the contents and
    clear it, if it is over a certain limit...

    Is the JTextArea so much different in managing content than the
    TextArea?

    Best,

    korcs
     
    korcs, Oct 16, 2007
    #1
    1. Advertising

  2. korcs wrote:
    ...
    >I use a JTextArea instance in my app to visualize program outputs.
    >
    >I have a LOT of output, ..


    It sounds like this ouput might better be written to a
    log. To see the live output in the GUI, start a thread
    that displays the tail of the log in the text area.

    What is this output that is so long that it crashes a
    JTextArea, but yet you can read it? At my average
    reading speed, I guess it would take 'days' worth of
    appends before the JTextArea had trouble (but I have
    not tried it).

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1
     
    Andrew Thompson, Oct 16, 2007
    #2
    1. Advertising

  3. korcs wrote:
    > Hi,
    >
    > I use a JTextArea instance in my app to visualize program outputs.
    >
    > I have a LOT of output, and I have experienced, that if I use
    > JTextArea instead of TextArea, after a certain time it does not take
    > any more appends, so my threads which are trying to use the JTextArea
    > to output something are stopping (start waiting for ethernity).
    >
    > Does anybody have an idea how could I avoid this? I suppose, that one
    > could check after or before each append the size of the contents and
    > clear it, if it is over a certain limit...
    >
    > Is the JTextArea so much different in managing content than the
    > TextArea?
    >

    Any approach like that will eventually choke if you just feed it data
    and don't discard anything. Why not use a list of Strings as a temporary
    line buffer and map it into a scrollable JTable to display its contents?
    When the list reaches, say 1000 entries, you drop the first item each
    time you append a new string. This would run forever without choking.


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, Oct 16, 2007
    #3
  4. korcs

    Ben Phillips Guest

    Martin Gregorie wrote:
    >> Is the JTextArea so much different in managing content than the
    >> TextArea?
    >>

    > Any approach like that will eventually choke if you just feed it data
    > and don't discard anything.


    If you feed it upwards of 2GB, maybe.

    I'd like to offer a differential diagnosis. This smells of deadlock or
    other concurrency issues and the OP explicitly mentioned appending to
    the JTextArea from multiple threads. If he's doing it *directly*, or
    even synchronizing on the JTextArea, rather than using
    SwingUtilities.invokeLater ...
     
    Ben Phillips, Oct 18, 2007
    #4
  5. Ben Phillips wrote:
    > Martin Gregorie wrote:
    >>> Is the JTextArea so much different in managing content than the
    >>> TextArea?
    >>>

    >> Any approach like that will eventually choke if you just feed it data
    >> and don't discard anything.

    >
    > If you feed it upwards of 2GB, maybe.
    >
    > I'd like to offer a differential diagnosis. This smells of deadlock or
    > other concurrency issues and the OP explicitly mentioned appending to
    > the JTextArea from multiple threads. If he's doing it *directly*, or
    > even synchronizing on the JTextArea, rather than using
    > SwingUtilities.invokeLater ...
    >

    No disagreement here, but I would point out that accumulating stuff in
    memory like that is a bad idea. Once the display program starts to swap
    (which it will at some point) its performance will deteriorate
    drastically: maybe that's what he's seeing. In any case, before it
    chokes itself it will have impacted everything else running on the computer.

    The approach I suggested is ugly in many ways, but would have caused
    minimal disruption to the OP's programs. Of course, what should have
    been done was to use a background logging program to capture the data in
    a log file. The display program would be rewritten to search, filter and
    display the log.

    Of course, if he IS using a *NIX its simple: use the system logger to
    write his log file and less or tail to view it. The only actual
    programming needed is to retrofit a syslogger interface to the source
    program(s).


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, Oct 18, 2007
    #5
  6. korcs

    korcs Guest

    Thanks for the replies.

    I will use the string buffering with erasing every entries older then
    the latest 1000.

    As a complementary solution I will log everything into a file.

    Best,

    korcs
     
    korcs, Oct 18, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ~~~ .NET Ed ~~~
    Replies:
    3
    Views:
    609
    Patrick.O.Ige
    Nov 16, 2004
  2. Dmitry Polyakovsky
    Replies:
    0
    Views:
    1,120
    Dmitry Polyakovsky
    May 13, 2005
  3. Will Handley
    Replies:
    2
    Views:
    587
    Anton Spaans
    Dec 11, 2003
  4. Richard
    Replies:
    10
    Views:
    667
  5. Laughlin, Joseph V

    Right-click brings up an option menu

    Laughlin, Joseph V, May 24, 2004, in forum: Python
    Replies:
    0
    Views:
    353
    Laughlin, Joseph V
    May 24, 2004
Loading...

Share This Page