| Author |
Server infinite loop causing freezing
|
Alex Rugav
Greenhorn
Joined: May 03, 2006
Posts: 19
|
|
|
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
Joined: Feb 03, 2004
Posts: 456
|
|
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
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
|
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.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
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
|
 |
 |
|
|
subject: Server infinite loop causing freezing
|
|
|