Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2127 > unrolled thread
| Started by | "Lee Graba" <lee.graba@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:37 +0000 |
| Last post | 2011-04-27 15:37 +0000 |
| Articles | 14 — 6 participants |
Back to article view | Back to comp.lang.java.gui
JTextArea append method d "Lee Graba" <lee.graba@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Lee Graba" <lee.graba@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Nigel Wade" <nigel.wade@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Nigel Wade" <nigel.wade@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Lee Graba" <lee.graba@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Tom Hawtin" <tom.hawtin@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Lee Graba" <lee.graba@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
Re: JTextArea append meth "tar" <tar@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
| From | "Lee Graba" <lee.graba@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | JTextArea append method d |
| Message-ID | <13adgejgteukg8d@corp.supernews.com> |
To: comp.lang.java.gui I have an application with many custom loggers, and a number of JTextArea instances for displaying the log entries written to the loggers. Each JTextArea has a thread associated with it that continuously pulls entries out of a particular logger and appends that text to the JTextArea. Thus, each entry written to a logger should show up in the associated JTextArea. The problem I have is that not all the log entries show up in the text area, and what shows up and what does not can change with each execution. I've put print statements before and after the log statements, and before and after the text area append, and all the expected log entries show up at all those places. Only in the JTextArea is there variability in what shows up. Is this a bug in JTextArea, or is this some known behavior? -- ================= Lee Graba leegraba@visi.com ================= --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <7d4ea3h4quq22nk4gb00u3c4ib4uj27pvd@4ax.com> |
| In reply to | #2127 |
To: comp.lang.java.gui >Only in the JTextArea is there variability in what shows up. >Is this a bug in JTextArea, or is this some known behavior? When you do that, you generate a repaint which creates an event that sits in a queue until the Swing thread has nothing better to do that repaint the JTextArea. Perhaps you are strangling the Swing thread so it can't keep up. -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Lee Graba" <lee.graba@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <13afoq6rvbud506@corp.supernews.com> |
| In reply to | #2130 |
To: comp.lang.java.gui Roedy Green wrote: >>Only in the JTextArea is there variability in what shows up. >>Is this a bug in JTextArea, or is this some known behavior? > When you do that, you generate a repaint which creates an event that > sits in a queue until the Swing thread has nothing better to do that > repaint the JTextArea. Perhaps you are strangling the Swing thread > so it can't keep up. But it would catch up eventually, wouldn't it? Also, when log messages don't show up in the JTextArea, it isn't always the last one. Sometimes one is missing, but a later log message does show up. It seems to be dropping some of the messages that are appended. -- ================= Lee Graba leegraba@visi.com ================= --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <75beacd59b9c4@uwe> |
| In reply to | #2132 |
To: comp.lang.java.gui Lee Graba wrote: >>>Is this a bug in JTextArea, or is this some known behavior? >> ....Perhaps you are strangling the Swing thread >> so it can't keep up. .. >...It seems to be >dropping some of the messages that are appended. I will suggest something I thought when I first saw this thread. "If you go to the effort of preparing an SSCCE* that demonstrates this behaviour, you might get more help." An SSCCE is a specific type of code, that is self contained, and can demonstrate a problem for others. This might be difficult to achieve for this problem, since you maintain it is with an existing, complex system, but please read the SSCCE document before you abandon the concept. It might simply require a 'main' class for the UI with a text area, itself creating several instances of a single Thread based update class. Your claim that the GUI class is somehow dropping the changes, is a hard one to swallow. An SSCCE that demonstrates the same behaviour might convince others. * <http://www.physci.org/codes/sscce.html> BTW - you have searched the *bug* *database* **, right? All the above is based on the (rash) assumption that your code does not simply expose an existing bug. ** <http://bugs.sun.com/bugdatabase/index.jsp> -- Andrew Thompson http://www.athompson.info/andrew/ Message posted via JavaKB.com http://www.javakb.com/Uwe/Forums.aspx/java-gui/200707/1 --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <75bebd32cc50f@uwe> |
| In reply to | #2139 |
To: comp.lang.java.gui Andrew Thompson wrote: >>>>Is this a bug in JTextArea, or is this some known behavior? Oh, but besides all that 'rabbiting on', note that Swing methods are not 'Thread safe'. See <http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable )> -- Andrew Thompson http://www.athompson.info/andrew/ Message posted via JavaKB.com http://www.javakb.com/Uwe/Forums.aspx/java-gui/200707/1 --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Nigel Wade" <nigel.wade@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <f89vq6$og3$1@south.jnrs.ja.net> |
| In reply to | #2140 |
To: comp.lang.java.gui
Andrew Thompson wrote:
> Andrew Thompson wrote:
>>>>>Is this a bug in JTextArea, or is this some known behavior?
>
> Oh, but besides all that 'rabbiting on', note that
> Swing methods are not 'Thread safe'.
>
> See
>
<http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable
> )>
>
However, JTextArea.append() is one of the few Swing methods which is thread
safe:
<http://java.sun.com/javase/6/docs/api/javax/swing/JTextArea.html#append(java.lang.String)>
My first thought was that the multiple threads appending to multiple JTextAreas
was the problem, and that wrapping the calls in invokeLater would be the
solution. Since the method is supposed to be thread safe this ought not to be
the case, if this is indeed the class/method which is being used. It might
still be worth trying anyway...
I agree with your other post. A SSCCE which demonstrates the problem might shed
some light on it.
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <75bfac75f756c@uwe> |
| In reply to | #2141 |
To: comp.lang.java.gui Nigel Wade wrote: >>>>>>Is this a bug in JTextArea, or is this some known behavior? .. >> See > ><http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable >> )> > >However, JTextArea.append() is one of the few Swing methods which is thread >safe: ><http://java.sun.com/javase/6/docs/api/javax/swing/JTextArea.html#append(java.lang.String)> My bad. .. >I agree with your other post. A SSCCE which demonstrates the problem might shed >some light on it. (Can't help but) agree with that. -- Andrew Thompson http://www.athompson.info/andrew/ Message posted via http://www.javakb.com --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Nigel Wade" <nigel.wade@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <f8a92d$s21$1@south.jnrs.ja.net> |
| In reply to | #2142 |
To: comp.lang.java.gui
Andrew Thompson wrote:
> Nigel Wade wrote:
>>>>>>>Is this a bug in JTextArea, or is this some known behavior?
> ..
>>> See
>>
>><http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable
>>> )>
>>
>>However, JTextArea.append() is one of the few Swing methods which is thread
>>safe:
>><http://java.sun.com/javase/6/docs/api/javax/swing/JTextArea.html#append(java.lang.String)>
>
> My bad.
99% (another of the 87% of made up statistics) of the Swing methods are not
thread safe. Unfortunately, to find out you have to read the API doc for each
method, so a it's a good rule of thumb to assume a method isn't thread safe
unless you know it is. Ensuring thread safety in Swing apps. is a very good
habit to get into, and won't hurt [anything except performance].
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Lee Graba" <lee.graba@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <13ailgpalksg35a@corp.supernews.com> |
| In reply to | #2141 |
To: comp.lang.java.gui Nigel Wade wrote: > Andrew Thompson wrote: > >> Andrew Thompson wrote: >>>>>>Is this a bug in JTextArea, or is this some known behavior? >> >> Oh, but besides all that 'rabbiting on', note that >> Swing methods are not 'Thread safe'. >> >> See >> > <http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable >> )> >> > > However, JTextArea.append() is one of the few Swing methods which is > thread safe: > <http://java.sun.com/javase/6/docs/api/javax/swing/JTextArea.html#append(java.lang.String)> > > My first thought was that the multiple threads appending to multiple > JTextAreas was the problem, and that wrapping the calls in invokeLater > would be the solution. Since the method is supposed to be thread safe this > ought not to be the case, if this is indeed the class/method which is > being used. It might still be worth trying anyway... > > I agree with your other post. A SSCCE which demonstrates the problem might > shed some light on it. > Actually, I have done this both ways, calling append in a separate thread, and within an invokeLater thread. Same results either way. -- ================= Lee Graba leegraba@visi.com ================= --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Tom Hawtin" <tom.hawtin@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <46b23a47$0$1619$ed2619ec@ptn-nntp-reader02.plus.net> |
| In reply to | #2141 |
To: comp.lang.java.gui
Nigel Wade wrote:
>
> However, JTextArea.append() is one of the few Swing methods which is thread
> safe:
> <http://java.sun.com/javase/6/docs/api/javax/swing/JTextArea.html#append(java.lang.String)>
Well, JTextArea is /claimed/ to be thread-safe. Now let us look at the code.
public void append(String str) {
Document doc = getDocument();
if (doc != null) {
try {
doc.insertString(doc.getLength(), str, null);
} catch (BadLocationException e) {
}
}
}
That clearly is not thread-safe.
99% of Swing is not claimed to be thread-safe. 99% of that which is
claimed to be thread-safe, isn't. Or thereabouts. You can just about
trust java.awt.EventQueue.invokeLater, but not a lot else.
Tom Hawtin
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <f67ha35dlbs1c1un13sq8acv1t6ukbr8b2@4ax.com> |
| In reply to | #2140 |
To: comp.lang.java.gui On Thu, 26 Jul 2007 10:42:11 GMT, "Andrew Thompson" <u32984@uwe> wrote, quoted or indirectly quoted someone who said : >Swing methods are not 'Thread safe'. There are a few exceptions, and JTextArea.append is one of them. http://mindprod.com/jgloss/swingthreads.html -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Lee Graba" <lee.graba@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <13aiplh7bjo6157@corp.supernews.com> |
| In reply to | #2139 |
To: comp.lang.java.gui Andrew Thompson wrote: > Lee Graba wrote: >>>>Is this a bug in JTextArea, or is this some known behavior? > >>> ....Perhaps you are strangling the Swing thread >>> so it can't keep up. > .. >>...It seems to be >>dropping some of the messages that are appended. > > I will suggest something I thought when I first saw this > thread. "If you go to the effort of preparing an SSCCE* > that demonstrates this behaviour, you might get more > help." > > An SSCCE is a specific type of code, that is self > contained, and can demonstrate a problem for others. > > This might be difficult to achieve for this problem, since > you maintain it is with an existing, complex system, > but please read the SSCCE document before you > abandon the concept. It might simply require a 'main' > class for the UI with a text area, itself creating several > instances of a single Thread based update class. > > Your claim that the GUI class is somehow dropping the > changes, is a hard one to swallow. An SSCCE that > demonstrates the same behaviour might convince others. > > * <http://www.physci.org/codes/sscce.html> > > BTW - you have searched the *bug* *database* **, right? > All the above is based on the (rash) assumption that your > code does not simply expose an existing bug. > > ** <http://bugs.sun.com/bugdatabase/index.jsp> > Yeah, a short example of the failure is certainly desirable. I'll see if I can produce one. -- ================= Lee Graba leegraba@visi.com ================= --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <oq6ha3pc6lsetavc7vvn73qp45go0fkiqb@4ax.com> |
| In reply to | #2132 |
To: comp.lang.java.gui >But it would catch up eventually, wouldn't it Not necessarily. If you keep it busy in a sleep or doing some computation, it will never be free to do service the GUI. If you have anything substantial to do is a GUI computewise that won't be done in a tenth of as second or so, spin it off on its own thread. It then must communicate with the GUI components with invokeLater. see http://mindprod.com/jgloss/swingthreads.html -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "tar" <tar@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:37 +0000 |
| Subject | Re: JTextArea append meth |
| Message-ID | <ymiwswgbdqy.fsf@blackcat.isi.edu> |
| In reply to | #2132 |
To: comp.lang.java.gui Lee Graba <leegraba@visi.com> writes: > Also, when log messages > don't show up in the JTextArea, it isn't always the last one. Sometimes > one is missing, but a later log message does show up. It seems to be > dropping some of the messages that are appended. This sounds like it might be a threading issue, despite the fact that append is supposed to be thread safe. Do the "dropped" messages ever appear later, out of order? Do they appear as expected if you also write them, say to System.out? -- Thomas A. Russ, USC/Information Sciences Institute --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web