Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

readUTF locking up GUI  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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: 21560
100
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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: 21560
100
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Did you just should on me? You should read this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!