• 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

NX: threading the Search method

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this will fall under the category of a newbie thread question.
In the contractor assignment, I have a Search button and a Cancel Search button. Only one is enabled at any time. A press of Search will fork a new thread to call a find method on my DatabaseInterface. This call eventually makes its way to the Data class and I have that search done in another Thread.
If the user then presses the Cancel Search button, the a Data class method gets called which kills the previous mentioned search thread by setting a boolean in its thread class. That boolean is part of the loop control test so it's like a polling mechanism, which I think is ugly.
It works (I tested it by creating a larger .db file and adding a sleep), but is what I'm doing bad practice, and if so as I suspect, what is the best way?
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stefan,
I don't see a problem with the way you are doing this. This is pretty much the way Sun recommend you stop a thread, and it is safe.
Personally I was not as nice as you - if the user started a search on my system, they were stuck waiting till the results came back I didn't loose any marks for that.
Regards, Andrew
reply
    Bookmark Topic Watch Topic
  • New Topic