• 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

telling when a thread has ended, without waiting for it

 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my first threading program so sorry if this question is stupid



i need to know when the thread finishes so i can remove the matchListener, but i don't want to hang everything up waiting (see code below) , or going to all the effort of starting a thread was pointless


so what is a usual tactic?

Thanks
p.s. and i just read a previous thread and am going back to work on my swing threads (edt was it?), from the MatchListener event handling
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I'm not sure what you mean by "without waiting for it". If the thread's not done yet, and you want to know when it's done, you generally have to either (a) force it to complete right now, (b) travel through time, or (c) wait for it to end. I don't know a good way to do (a), or any way to do (b). But (c) is pretty doable. There are, however, much better ways to do it than the code you showed, so hopefully that's what you're asking about. Probably the best way given the setup you envision would be to simply call t.join(), where join() is a method defined in the Thread class. If that doesn't work for you, try reading about wait() and notify(), defined in Object. Does that help?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couldn't the "run" method remove all match listeners from itself before it finishes? Or you could pass in a reference to the specific listener that should be removed.
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Couldn't the "run" method remove all match listeners from itself before it finishes? Or you could pass in a reference to the specific listener that should be removed.


I like this idea, but there is other stuff as well (setting the search button to enabled, and the stop button to disabled).

last night (in bed) i was thinking maybe i could send a finished event, or set up a timer to check every 2 seconds.

Mike: by not waiting i meant not sitting in a loop checking the status every time round the loop.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either sending an event (if there is more than one object that should get notified) or a callback interface would work.
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Either sending an event (if there is more than one object that should get notified) or a callback interface would work.



oh i haven't got a callback interface in yet, thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic