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.
Joined: Feb 03, 2004
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...
author and iconoclast
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.