Thread: How to tell when the thread is finished AND how to kill it?
Hi there,
I have a thread that runs in the background and does this:
class MyThread implements Runnable
public void run()
Stopper stopper = new Stopper();
//do something that takes some time
stopper.stop();
System.out.println("total time "+stopper.getTime());
}this works fine (I have a swing gui where I click a button and this thread runs and it's ok. PROBLEM IS, when I click the button again (to re-activate the thread) it seems that the stopper is not null but still counting the time (I was under the impression that ...= new Stopper() will create a new object type Stopper).
so -
1. How can I tell when thread is finished?
2. How do I kill this thread once it is finished?
the invocation:
public void actionPerformed(ActionEvent arg0)
Thread t = new Thread( new MyThread());
t.start();
}THANK YOU!
You have not posted to code for Stopper, so it's impossible to reason about that
1. How can I tell when thread is finished?
Use Thread.Join() or Thread.isAlive()
2. How do I kill this thread once it is finished?
You can't and you don't. Just let the method the thread is running exit normally. Sometimes that means putting in a boolean variable to control a loop, and then exiting when the boolean is false.
Another thought - you could set the thread as a Daemon thread - when you don't have any non-daemon threads running, java will exit.
Similar Messages
-
How to tell when the interface is down and was last active.
Is there a function within Cisco Prime Infrastructure 2.0 (2.0.0.0.294) that will display the last time that an interface was active? Our end switch hardware is as follows C2960s-48fps and C3750-48PS-S.
See below for command and command output from the console of one of our switches.
C2960s-48fps#show int gi1/0/6 | include Last | proto
GigabitEthernet1/0/6 is down, line protocol is down (notconnect)
Last input never, output 1w6d, output hang never
Above is an example of one interface but can this be accomplished for all interfaces on the said switch?
Thanks
Message was edited by: Bobby Sasser The following is the response that Cisco TAC sent. Not happy with this answer! Unfortunately , Prime doesn’t collect those precise information. So apparently you won’t be able to poll that information from the device.You have not posted to code for Stopper, so it's impossible to reason about that
1. How can I tell when thread is finished?
Use Thread.Join() or Thread.isAlive()
2. How do I kill this thread once it is finished?
You can't and you don't. Just let the method the thread is running exit normally. Sometimes that means putting in a boolean variable to control a loop, and then exiting when the boolean is false.
Another thought - you could set the thread as a Daemon thread - when you don't have any non-daemon threads running, java will exit. -
Can iTunes be set to play only one song and then stop when the song is finished and not go on to play another unless commanded?
If you uncheck all of the songs, they will only play if explicitly commanded. Command-click in a checkbox and they will all be unchecked. Command-clicking again will check the all again should you want to do that.
-
How can we track the flow of Delegation and how it differ with subtype
HI,
Do any can tell me the difference between the Delegation Object and SubType Object, and how to track when the delegation object is triggered and what is the need of delegation and the subtype.
Issues is: I have developed the delegate object and iam not able to track that delegate object whether that object is triggered or not, now i want to know that whether my delegated object is triggered or not.
Thanks,
Ravi Kumar.hi
use this link
http://www.erpgenie.com/sap/abap/bor.htm
Cheers
Snehi -
How to tell when the load to start
Hi,
don't even know where to look for the answer, so I apologize
if this topic was already opened. Here's my case. In main flash
movie load another flash movie, where different items come from
left and right side of the screen (full screen window). After a
click on one item, all the item go the sam eway off the screen and
another movie loads. Question. How to tell the flash that first all
the items must go off the screen and then unload that movie and
load the new one?
THX for the helpjo3 wrote:I'm curious to know what time my system lost power, whats a good way to tell? I have been checking the logs to get the last entry times but was curioius if there were other methods of telling when the box's power was interrupted?
A rather ghetto way of doing it:
#!/bin/bash
log="/var/log/uptime-poll"
pollsecs=10
echo $$ > /var/run/uptime-poll.pid
if [[ -f "$log.tmp" ]]; then
echo "Lost power at: `cut -d';' -f2 "$log.tmp"`" >> "$log.log"
fi
while :; do
date +'%s;%D %T' > "$log.tmp"
sleep $pollsecs
done
...and in /etc/rc.local.shutdown...
killall $(cat /var/run/uptime-poll.pid)
rm /var/run/uptime-poll.pid
rm /var/log/uptime-poll.tmp
Last edited by Wintervenom (2009-08-29 06:37:29) -
How to tell when the system was shut down?
I'm curious to know what time my system lost power, whats a good way to tell? I have been checking the logs to get the last entry times but was curioius if there were other methods of telling when the box's power was interrupted?
jo3 wrote:I'm curious to know what time my system lost power, whats a good way to tell? I have been checking the logs to get the last entry times but was curioius if there were other methods of telling when the box's power was interrupted?
A rather ghetto way of doing it:
#!/bin/bash
log="/var/log/uptime-poll"
pollsecs=10
echo $$ > /var/run/uptime-poll.pid
if [[ -f "$log.tmp" ]]; then
echo "Lost power at: `cut -d';' -f2 "$log.tmp"`" >> "$log.log"
fi
while :; do
date +'%s;%D %T' > "$log.tmp"
sleep $pollsecs
done
...and in /etc/rc.local.shutdown...
killall $(cat /var/run/uptime-poll.pid)
rm /var/run/uptime-poll.pid
rm /var/log/uptime-poll.tmp
Last edited by Wintervenom (2009-08-29 06:37:29) -
How to tell if the MBP is Original and Macs 4 Cash
Hi-
How do I tell i my MBP is Original or the other? I remember when I got it about 2 years ago it was not the "original" at that time but if the 2 now are the unibody and original, I have the original.
Anybody do business with Macs 4 Cash? Reputable??
Also, I had to do a google search on some number to find out if they put the aster speed HD in my MBP because that was not listed in System Profiler. Sure enough the number brought it up and they did but I forgot what number I used and how I did the search.
Does anybody know? I tried just the serial number and zero returnsYou're correct that your MBP is the "original" version, but there are many different "original" revisions. What else do you want to know about it? Download MacTracker from versiontracker.com to get more info or ask here exactly what else you want to know.
It sounds as if you might be selling your Mac? If so, you'll always get a better price selling it outright, rather than to a reseller, as they have to turn around and sell it for a profit, and maybe offer a guarantee and service.
For HD speed, open Disk Utility, copy the manufacturer's model number, paste it into a google search and you'll get your HD info.
http://support.apple.com/specs/
http://www.appleserialnumberinfo.com/Desktop/index.php
http://www.chipmunk.nl/klantenservice/applemodel.html
Message was edited by: tjk -
How do I reset the security questions? And how do I unlock the account.
I just got the iPhone 4s and wanted to get music. Well it was asking for security queation answers that I put in and it kept saying it was wrong. So now I'm blocked out of iTunes and cant download music. Help me please...
Go here to reset your password. Then you can reset your security questions after logging in.
If that doesn't work, contact Apple ID Support. -
How to tell when downloading raw and jpeg images is complete
i just installed lr 3 and have a new mb 8 gb of ram and dont know how to tell when the download of raw and jpeg is done .ie the time from thumbnail to full down loads
There should be a progress bar in the upper left corner when in library module.
-
How to deal with the mouse events when the thread is running
Hi everybody,
I have a problem with my program.
Now I want to present a picture for some time in the Canvas,then automatically clear the screen, but when the user press the mousebutton or keybutton, I want to stop the thread and clear the screen.
How can I receive the mouse event when the thread is running?
Thanks,I use my code in a GUI applet.
I try to use the code tag, it's the first time.
Image im=sd.getStimulus(obj);
if(pos==null){
g.drawImage(im, (w-im.getWidth(null))/2,(h-im.getHeight(null))/2,null);
}else{
g.drawImage(im, pos.x,pos.y,pos.w,pos.h,null);
try{
sleep(showtime);
// Thread.sleep(showtime);
}catch(InterruptedException e){}
if(pos==null){
g.clearRect((w-im.getWidth(null))/2,(h-im.getHeight(null))/2,im.getWidth(null),im.getHeight(null));
}else{
g.clearRect(pos.x,pos.y, pos.w, pos.h);
} -
J2ME Application is slow even when the thread is finished
Hello everyone
I've been searching for a solution for a whole day but haven't found any thing.
My problem is that when I start a thread, after it finishs, my application seems to be a bit slower. The more I repeat, the slower it seems.
Does anyone know how it can be that? I tried to just do a simple work such as assign i = 1; in the run() method of this thread, so I am pretty sured that the thread finished completedly.
Thanks in advance- how are you forking the thread? [show code]
- is the lag in the emulator or on the device?
- what ide/device are you using? -
How can I tell when the NEW firmware is available ?
Although the firmware became available for the 'z2 tablet' very quickly - nothing has appeared for the phone (UK - SIM free).
I have tried the update several times (with my PC) & am just told 'up to date'....
I remember with the 'xperia s' I had to check a code (on a sticker inside the rear of the phone) to tell when it was available for me - how do I do this with the Z2 ?Unfortunately we are unable to confirm specific date for any particular firmware release due to the nature of the approval process.. For further information regarding the approval process please see here.
http://talk.sonymobile.com/t5/FAQ/The-software-update-collection-topic/m-p/348066#U348066
What are your thoughts about this forum? Let us know by doing this short survey.
- Official Sony Xperia Support Staff
If you're new to our forums make sure that you have read our Discussion guidelines.
If you want to get in touch with the local support team for your country please visit our contact page. -
SCN - How do I close the Thread of communication
SCN - How do I close the Thread of communication
SanjayBy changing the status of your discussion.
from Not Answered to Answered or Assumed Answered.
Also read the blog to know more How to close a discussion and why -
When I switch libraries I "lose" the majority of the material in my main library (or at least I can't see it) and can only restore it by repairing the database. Can anyone tell me why this is happening and how I can resolve the problem? Thanks
I seem to have found a way around it. Rather than switching libraries by going into files/switch libraries I used Aperture Preferences to change them. I've done it a couple of times and it appears to work OK.
That is an interesting finding. It suggests, that your "Preferences" file "com.apple.Aperture.plist" may have been corrupted and you fixed it this way. Can you now switch between libraries the usual way? If not, I'd try to remove the "preferences" file from the user library to the Desktop and relaunch Aperture.
The Aperture 3: Troubleshooting Basics:http://support.apple.com/kb/HT3805
describe how to remove the user preferences. -
Hi
I read the following sentences in FAQ:
{forum:id=123} - Displays link to forum 123
{thread:id=12345} - Displays link to thread 12345
{message:id=1234567} - Displays link to message 1234567
{user:id=1234} - Displays link to user 1234 (numeric ID)But I don' know where I can find the forum:id, thread:id and message:id
Thank for your help
hqt200475bigdelboy wrote:
trent wrote:
bigdelboy wrote:
As far as I am aware the threadID and the messageID never appear in the same URL.At this top of this thread, there is a link for 'Last Post'
This points to: Re: How can I find the Thread ID containing both thread and message id's
In your example, the 'Whoever' bit is just plain text. i.e. no hyperlink (for me).
I think you are talking about the links on the list of threads, whereas Aketi is referring to the link in the actual thread (at the top of the page).I feel a litlte outgunned {noformat};){noformat} ..... however I currently stand by my postulation their is no URL hyperlink where both the threadID (2234623 for this thread) and messageID (eg 9651344 for this post) are present in the same URL. URLs with the messageID obviously link to the thread on the basis the message is a child of the thread, but the threadID is not explicily present in this case.
Rgds - bigdelboy
http://en.wikipedia.org/wiki/A_Funny_Thing_Happened_on_the_Way_to_the_Forum ( {forum:id=29} )
http://forums.oracle.com/forums/help.jspa
Waht a plonker bigdelboy is!
I think you are talking about the links on the list of threads, whereas Aketi is referring to the link in the actual thread (at the top of the page).I agree entirely. Apolgies to all. You are SO right.
Permlink Replies: 12 - Pages: 1 - Last Post: Jun 10, 2011 8:23 AM Last Post By: bigdelboy Threads: [ Previous | Next ]
Re: How can I find the Thread ID
Maybe you are looking for
-
When I look up the 250+ new features of Mac OSX Lion, under address book, there's a new feature that interests me. "Address Book lets you quickly access the social network profiles for your contacts, including Facebook. Press and hold an email addres
-
When I installed iOS5 on my IPhone4 and selected ICloud for my storage location, all my Notes disappeared off my IPhone & Desktop. Where are they?
-
Everytime I connect to iPad, itunes gives me a warning message. This iPad cannot be used because the Apple Mobile Device service is not started. I looked at troubleshooting in Apple site and resetting it, but no success yet!
-
i can not get to options window-content panel-where i was told i can drag it to my desk top if you have a link or any way other then that i can get this resolved. on ie all i had to do was right click my mouse.please help thank you sal
-
2 license version of PhotoShop Elements
Does Adobe have a 2 License version of PhotoShop Elements 11?