• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

readUTF locking up GUI

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello (world),

The following code works when used outside of netbeans for when receiving input from the server:
while (true) {
jTextArea1.append("\n"+in .readUTF());
}

However, whenever used in netbeans, the entire GUI freezes until I kill the server. Furthermore, it's actually "working" in so far as when the server is finally shut off, the GUI is finally updated to reflect all of the messages that have come in.

What am I doing wrong? I moved to netbeans in order to make a nice gui -but now the application has stopped working Any help would be appreciated for this javaranch newbie. By the way, the server is sending out a writeUTF().

Not sure if this is the right category for this or not.

Thanks in advance!
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html

In other words, don't call methods that can take a long time or block in the Event Dispatcher Thread.
 
Roger Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you sir! Very interesting article- I'm blocking the Event Dispatcher Thread then. I'm trying to figure out how to use the invokeLater() method but am still trying to figure it out. Thanks again and will post again if I have additional questions.
 
Roger Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I have now:


Where appendMessage() is:


Only problem is, it doesn't work. Actually, obviously as a result of my lack of complete understanding and therefore incorrect implementation, it makes the gui lock up even more.

Any ideas?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is the part that blocks the EDT


try it like this - the rest of the code should be OK

 
Roger Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's great! What I ended up doing a little earlier was:



and:



Which works! I think that's basically what you had Michael but yours is much more succinct. Thanks so much for the help, I really appreciate it!
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Potentially this can already block your GUI:
If the host is unavailable, or the connection between the two machines is slow, this call can take longer than you expect.
Remember, any I/O, networking or database access is potentially blocking / slow, and shouldn't be handled in the EDT.
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic