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

Long thread process?  RSS feed

 
Dan Temple
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I am going to be writing a program that spawns a single thread to do the basic processing of the program, while the event dispatch thread listens to user events. As the loop that the basic processing is performed in is not trivial, is the only way to exit gracefully from this thread to poll some variable that is affected by user events? This would mean that in order to keep the GUI responsive I would have to keep repolling the variable after any time consuming processes within the loop. This seems kind of crude doesn't it?
i.e.
While(Variable says keep going)
{
Poll Variable
Stuff
...
Stuff
...
Poll Variable
...
Stuff
...
Poll Variable
etc
}

Is there a more elegant solution?
Dan
 
NIKHIL EROS
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Dan,
can u be please more illustrative in ur problem. the problem on threads, in particular event despatch threads need more care and understanding of concepts.
please explain ur problem in more convenient way!!
regards
Nikhil.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dan Temple:
Is there a more elegant solution?
We had a religious discussion about that a while ago, not everyone is very pleased with the idea, but if you are looking for ways to interrupt the processing (rather than merely direct it to do something) you can poll usingYou can catch the exception at whatever level is appropriate to your code. To interrupt the worker thread, just thread.interrupt() it. If there are many places where you need to poll it makes sense to put the polling code in a method.
Some feel this is an abuse of the interrupt facility and you should only use interrupt() if you are actually wait()ing or sleep()ing. I feel that it's exactly what the Thread.interrupt() method was conceived for, provided that you really want to interrupt an ongoing operation.
- Peter

[This message has been edited by Peter den Haan (edited November 22, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!