5

The java doc says the append method is thread safe. However, I recall that when I tried using the append to the text area from different threads (several months ago), I get jumbled text where thread 1 would append some characters and thread 2 would append some other characters. So instead of getting STRINGstring in the jtextarea, I get SstTrRINingG.

What differences would there be between:

  1. synchronizing the append
  2. bottlenecking appends from different threads through a threadpoolexecutor
  3. using invokeLater on the EDT

or are they all fine for fixing the issue? Thanks

lgp
  • 325
  • 4
  • 12

2 Answers2

7

While append() was thread safe with respect to the EDT, append() in Java 7 is not. Appends using invokeLater() will be processed in the order in which they are enqueued. A critical examination of the other approaches would require an sscce.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

All your solutions seem ok to me. Since you will need to use some form of Invoke to update the UI anyway, it's probably best to just use invokeLater to avoid any other complications.

Tudor
  • 61,523
  • 12
  • 102
  • 142