• Post Reply Bookmark Topic Watch Topic
  • New Topic

Server infinite loop causing freezing  RSS feed

 
Alex Rugav
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a server listening to a client through an infinite loop.This is causing my main screen to freeze ,menus disappear.what could be the solution to separate the loop from the swing GUI.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
many options.

you could take care that your listener thread releases it's cpu consumption by using the sleep() method.

but your situation sounds like a perfect example of the observer pattern. as you did a gui already, you should be familar with the conception of listeners registering themselves at an observable object. so they get notified if (and only if!) some state at the observable object changes.

i'm sure you have dozends of hits if you use this forum's search function...

jan
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My thought is that you've got your infinite loop in a GUI event handler; you didn't say, but the "main screen" reference makes me think that the server has a GUI itself. If this is the case, then the solution can only be (perhaps in addition to previous input) to move that loop into its own thread. If you put a long-running loop in an event handler, then no other events are handled, nor is the screen repainted, until that loop terminates.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a link to a tutorial that explains just how to do what Ernest suggested: http://java.sun.com/products/jfc/tsc/articles/threads/threads3.html
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!