Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Making application halt execution for a period  RSS feed

 
Stavros Kanarakis
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I hope that this post indeed belongs to this category.

I have implemented an application for monitoring and controlling some external simulation tests.
The application reads an XML config file, and based upon that information, it controls the execution and monitoring of external application (non-Java) simulation tests.

The logic is that my app is executing a remote test, then at some time, it stops the test and waits till that test cleans up.
This waiting period can vary from 10 seconds to 1 minute.

In my application, I managed to do this halting by entering a while loop and using Thread.sleep() method. In each while iteration, I am checking some value that will help me avoid an eternal loop.

Application works fine.
However, my problem is that while my program waits for the simulated tests to clean up (being inside the while loop), it stops responding due to the sleep() method. You can only re-get control of it when while loop is exited.

Is there any other more efficient way to make my application halt and wait for something to happen before going to next command? Something that will make me avoid a freezing application for that period of time?

I am attaching you the while loop code segment





Thanks
Stavros
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently you're performing the functionality in the same thread as the one that handles UI events. Separate the functionality into a different thread and than you should be fine.
 
Stavros Kanarakis
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick answer.

I have though of this solution, however I am a bit frustrated by the fact that in my UI class code, I have a lot of data structure members (primitive multidimensional arrays, object arrays and a lot of single data members/class methods).
All these members are containing valuable information about the tests I am trying to control and need to be accessed inside the while loop.

If I start a new thread waiting for a test to finish, how will I be able to access those data members of UI class?
From the code segment, you can see that objects/primitives/class methods like

runningIPSWindows
hasPreviousTestStoppedNormally
updateTableCells
updateTabeCellsToError
updateTotalRemainingTime

are all needed and these are declared in the UI class (I am using Netbeans GUI builder project).
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stavros Kanarakis wrote:I have though of this solution, however I am a bit frustrated by the fact that in my UI class code, I have a lot of data structure members (primitive multidimensional arrays, object arrays and a lot of single data members/class methods).


Therefore it is important to separate concerns. Because you have mixed your data (model) with your GUI (view) it's hard to change things. I would advise you to look at some models such as MVC. It would be a big refactoring tour but it will make your program more flexible.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!