aspose file tools
The moose likes Java in General and the fly likes Server infinite loop causing freezing Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Server infinite loop causing freezing" Watch "Server infinite loop causing freezing" New topic
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
    
  13

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
    
    2

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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Server infinite loop causing freezing
 
Similar Threads
Infinite looping in 'for' and 'while' loops
Confusing Output
WA #1.....word association
Heap Space Error
.JAR file appears to stop running