• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Long thread process?

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic