wood burning stoves
The moose likes Threads and Synchronization and the fly likes Question about Multithreading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Question about Multithreading" Watch "Question about Multithreading" New topic

Question about Multithreading

Jack Tauson

Joined: Mar 27, 2014
Posts: 10
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.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

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

Joined: Feb 07, 2010
Posts: 163

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)

Please, visit me for some cool tech post at www.ourdailycodes.com
I agree. Here's the link: http://aspose.com/file-tools
subject: Question about Multithreading
It's not a secret anymore!