Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Multithreading

 
Jack Tauson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using multithreading and JavaFX to grab the data from a database, so I update the GUI using progress bar. Say for example 10 progress bar for 10 threads. If I have 100,000 records in a database from which I am planning to
pull using 10 threads then I am pulling 1000 records at a time using 10 threads.

My Question is:

1) Is it possible to have a stop button next to 10 progress bars and stop a particular thread if I wish to. As far as I know, once the threads are started in a multithreaded environment, it can't be stopped unless they finish ?

Please correct me if I am wrong.

Thanks
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure you can stop a thread. You may have read that you can't, but what you can't do is to call its "stop" method. Here's how you write a thread which can be told to stop:



Then when you want to tell that thread to quit, you just set its "quit" variable to true.
 
Luan Cestari
Ranch Hand
Posts: 166
C++ Redhat Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I totally agree. I would just say that the 'manager' thread should try to interrupt (due it maybe in some kind of lock process, f.e.) and also start ignoring the threads as well (not trying to wait all to finish, as it can be and a heavy processes) (or you can create a thread just to take care of this, so you could wait the process, even if the user doesn't want them anymore)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic