Results 1 to 9 of 9
Thread: How to know when a thread ends.
- 10-21-2008, 10:13 PM #1
Member
- Join Date
- Feb 2008
- Posts
- 60
- Rep Power
- 0
How to know when a thread ends.
Hi all,
I have a multi-threaded program. This program, lets say spawns 10 threads. I would like to update a variable when each thread finishes its job.
The reason why I am asking this, is because I would like to show something like progress bar (not really a progress bar, but display a precentage of job completion, while the program is running).
I have this thaugh, and someone please correct me if I am wrong.
I have the following classes
- MainProgram.java
- MainProgramThread.java
- MainProgramProgressThread.java
If MainProgram creates 10 instance of MainProgramThread class, I would like to decrement a counter (which has the maximum number of threads running)
On the other hand, MainProgramProgressThread class will only display the progress percentage (this will be calculated) so long as the number of counter is greater than zero when this value reaches 0, then I would like the ProgressThread to stop.
So, my question is how can I know when a thread ends?
Or if there's another way of doing what I would like to do, I am open to ideas.
Thanks in advance...
- 10-21-2008, 11:09 PM #2
Have the thread call a synchronized method before it exits.
- 10-23-2008, 05:04 PM #3
Member
- Join Date
- Feb 2008
- Posts
- 60
- Rep Power
- 0
Thanks once again Norm. It worked!
- 10-24-2008, 10:55 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you have solve the problem please mark the thread as solved. It's really helpful to all.
- 10-24-2008, 11:02 AM #5
You can also use executor service ... which is bundled in java 5 .. it has feature of getting the success flag once the flag has finished processing.
- 10-24-2008, 11:17 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I'm not exactly clear what you mean. Are you talking about use of a dummy flag, that's the word I use, to process a thread. Like this.
Java Code:public void run() { while(true) { // Do the thread process here } }
- 10-24-2008, 11:20 AM #7
actually it is based on de' lough concurrent package and is handy in managing thread pools with executors and worker threads.
- 10-24-2008, 11:20 AM #8
and it has a getter method which returns the true and false for completion of thread.
- 10-24-2008, 11:22 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I've never work on with that. Better to check about it more. Thanks for the infor.
Similar Threads
-
passing a value from parent thread to child thread
By sachinj13 in forum Threads and SynchronizationReplies: 7Last Post: 09-07-2008, 09:06 PM -
Does any file in an FTP server ends up in an HTTP server?
By islamfunny in forum CLDC and MIDPReplies: 4Last Post: 08-15-2008, 04:30 PM -
data from the main/GUI thread to another runnin thread...
By cornercuttin in forum Threads and SynchronizationReplies: 2Last Post: 04-23-2008, 10:30 PM -
If JNI thread call the java object in another thread, it will crash.
By skaterxu in forum Advanced JavaReplies: 0Last Post: 01-28-2008, 07:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks