Timer that will interrupt a thread

How do I create a timer that will interrupt a thread?
I need to put this timer inside the thread, and I should be able to manipulate the time.
I have managed to create an inner class that act as the timer. But, I can't make the timer to interrupt the main thread.
Can anyone help me? Is there any simpler way to do this?

See Thread.interrupt()
If you call this while a thread has called sleep() and is waiting, this should then throw an InterruptedException
BTW, in the case where you have a thread that reading from a socket / inputstream, and blocked on read(), the way that I always use to unblock my thread is to simply close the stream, which generates an IOException and unblocks the thread.
...And BTW Thread.stop() has never been implemented and does nothing!
Edited by: tjacobs01 on Jan 3, 2008 6:09 AM

Similar Messages

  • For the times that I'm here Thread

    It's been quite a while since I've Iast posted something, mainly because I've been busy with all kinds of stuff.So I decided to make a thread in which I can just post all of those long stories, that I know you all love haha... Let me start with an update, on most things... Workwise:So far everything is going great, we recently offically founded our new company (the one I basically "developped") and all seems to be going according to plan.We've already got a good bond with two of our new companies, and I can truly see this becoming a succes. Seeing as I've practically raised this new company it sort of feels like my "child"   My uncle also offered me the chance to start working 5 days (instead of 4) with an increased paycheck, so that's pretty awesome as well.  Furthermore, that military selection process I've been going through for the past half year is going great as well. I actually had one of my dreams come true last wednesday, when I basically had one of my last selection tests. For this test I had to navigate and do some voice marshalling in a helicopter, we did two 40minute flights in an Alouette 3 helicopter, and it was just incredible, I had a large grin on my face throughout most of the flight The test was quite (very) tough, but it went pretty well! I did make a few mistakes, but I was able to "fix" them myself without any further trouble. Right now all I can do is wait, and see whether they'll let me pass (I'm expecting a call next week). What's really a relief for me right now, is the fact that should I not pass, at least I'll have a great alternative (unlike last year when it felt like my life depended on it)   So that's all going great, as for the rest of me right now:Like I said, I've been quite busy lately, work/ learning for that test aaaand going out (way too often).Last year I only went out every two weeks or so, or even less; over the past few weeks I've been going out 2-3 times a week A while back I decided to go out on a (girl)friend's brithday, and got home at 3:30am, even though I had to get up at 5am, and I had already gone out twice that week... but oh well, I've been having a blast which is all that matters. I'm not going out tomorrow night though... (which has "nothing" to do with the fact that I'll be going to a festival tomorrow...  ) But yeah, almost everything is going great! [edit, for meh story]How have you all been?

    I had my medical and physical test today... passed it!   (long version in spoiler tag)The medical evaluation consisted of 6 parts:
    -Allergy test
    They tested whether or not I was allergic to certain things (such as pollen), luckilly I wasn't.
    They would put a drop of a certain substance on your skin, then ***** through the skin with a needle so that the substance could enter your body and then you'd have to wait for a reaction.
    Some were talking about it being quite an annoying/ painfull test, but for some reason I didn't feel anything haha
    -Hearing test
    Just a simple hearing test where you had to click a button if you heard a beep.
    I was a bit afraid of this one seeing as I once had quite a painfull hearring "accident" when a music teacher forgot he had his speakers turned up all the way whilst displaying a beeping noise (ironically) caused by hearring damage to prevent us from listening to loud music...
    luckilly though I scored really well on that test, about 1.5 to 2 times better than the min. requirement.
    (they also tested my eardrums using airpressure)
    -Blood/ urine test
    Self explainatory, passed it.
    -Eyesight tests
    Pretty much everything you can test, again, had great results.
    During one of the tests (field of view) you had to focus on one little light, whilst other very small lights were projected arround it, and you were tested whether or not you could see them; out of 240 light that were shown I only made one mistake (probably just blinked hahah). 
    There was however one test that tested your visions field of depth, and for some reason it didn't work for me, they tested it in a different way on me after that and it turned out everything was okay (luckilly).
    -Lung test/ heart test 
    They tested the volume of my lungs and made a "film" of my heart, everything was great and above min. requirements
    Then there was the physical part, which consisted out of three segments:
    -Bicycle test
    We had to first peddle going 80 rpm for two minutes, then we had to sprint as fast as possible to 120 rpm after which you had to get back to 80, then we had to speed up to 140 and back to 100 and last but not least you had to fuly sprint (at arround 5 minutes) and keep sprinting for  30seconds. 
    I could've done better at this part, seeing as I couldn't keep my speed leveled whilst sprinting at the end. The thing is I mainly jog/ run, I don't really ride my bike that often... but still it wasn't that bad.
    -Strength test
    We were tested on our leg strength, and the strength form our abs and back.
    During the leg strength test you had to push away this plate infront of you with as much force as possible, which went really really well the second time I did it, I was way over the required strength
    The abs and back part basically consisted of being squished in between to plates, and then having to push those plates away from you with as much force as possible; which went quite well as well.
    And there was also a small jump test, couldn't go wrong basically.
    -Running test
    We were placed on a threadmill with a mask covering our face which regulated/ held track of both the O2 input and CO2 output etc, and we had to run for as long as we could (up to a certain point).
    The threadmill would increase in speed by 0.5km / hour every minute, untill it reached its max of arround 15km/ hour.
    On average you had to run for about 8-12 minutes, and I ran 12,5 minutes, so I was really happy with that.
    All in all a positive result for the physical part, the lesser performance on the bike test was compensated for by my results on the other tests.Right now I'll just have to wait for a little while again.I've basically passed everything and they're now gonna select the best candidates to fill up the open positions. Luckilly from what I know, there aren't that many who passed the tests, and there are actually quite a few open spots  It feels weird having started out with a group of 40 men, and now being the only one who's left (/ made it through every test). There are a few more candidates, but they came from a different group.

  • How can I make a timer that will record elapsed time up to 15 hours with a PCI-6503E DAQ card?

    I'm a beginner LabVIEW programmer, but need to take measurements of elapsed time from the start of data acquisition for up to 15 hours. I'm using a PCI-6503E card. Looking at examples on the web and LabVIEW, itself, I was only able to find a way to take time measurements with a DAQ card up to 167 s, unless two counters were tied together, but there are no instructions on how to do that. Could someone help me? Thanks.

    I suggest you to look in the Resouce Library: inside it there is plenty of useful examples.
    I found this VI with two cascaded timers in the Measurement hardware > Counter/Timer > Event/Time Measurement cathegory:
    http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?​openagent&5293158F4EC950C4862568C1005F6CD9&cat=C70​29C9ACBD3DF7386256786000F8EE6
    Hope this helps.
    Roberto
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Interrupting Main Thread

    Hi,
    Is there a way to interrupt a Thread.sleep() (ie the main Thread executing)
    I was also wondering if when you call Thread.enumerate() if
    it returns an array of all the new threads which have been created and still exist at that point in time ?
    The reason is, sometimes after a period of time after my application has been running, and 'rdate' will happen on the system and if the time is set backwards, any Threads currently sleeping do not wake up and need to be interrupted.

    Did you look at the API docs?
    Thread.interrupt() will interrupt a Thread. You could
    keep a reference to all your sleeping threads and call
    interrupt() on each one when you want. This will
    interrupt them from their "sleep" and throw an
    InterruptedException.
    http://java.sun.com/j2se/1.3/docs/api/java/lang/Thread.
    tml
    http://java.sun.com/j2se/1.3/docs/api/java/lang/Interru
    tedException.htmlYes, I do understand how interrupt will interrupt a thread from a sleep. I should rephrase the question - There are currently a number of threads executing (there are over 2000 classes). This particular class does not know anything about the threads executing and their current state. When the system time is changed (by an rdate (unix)) this class is notified by a C program (which calls the rdate). Any threads in a sleep at this current time will come out of the sleep because time has gone backwards - so now the currentTimeMillies is returning a value less than the time it started the sleep with. Now ... I need to interrupt all of the threads which are currently sleeping - which this class does not have a handle to, it is only for being notified when an 'rdate' happens. I have worked out, I can use Thread.enumerate(Thread [] threads) to get a handle to all of the current threads. I can interrupt all of the threads by looping through this array. What I was asking is ... If a class uses a Thread.sleep - so it is telling the main thread to sleep - how do I interrupt it (I have worked out the enumerate() call will even return the AWT thread, so I assume I can interrupt it)
    Now another problem is, the interrupt will not interrupt threads which are currently in a wait() state.

  • Make a Thread to get sleep for a time that has decimals

    I need a Thread to get sleep for a time that has decimals, for example 3,5 miliseconds but is not possible because the Thread.sleep() admits only long. Is not other way to do it?
    Thanks

    dannyyates wrote:
    Well, there's sleep(long millis, int nanos), but to be honest if you're requirements are that tight, sleep() is probably not the right tool for you because if doesn't really guarantee any level of accuracy.That's true, the accuracy of sleep() depends rather on the underlying OS and hardware. As the docs say:
    "Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, *subject to the precision and accuracy of system timers and schedulers*. "
    Just run this simple test program, it gives interesting results:
         long start, stop;
         for (int i=0; i<100; i++) {
              start = System.nanoTime();
              try {
                   Thread.sleep(5);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              stop = System.nanoTime();
              System.out.println("The thread slept for " + (stop-start)/1000000.0 + " ms");               
         }On my Windows XP with dual core CPU I get:
    The thread slept for 5.801576 ms
    The thread slept for 5.778108 ms
    The thread slept for 6.134019 ms
    The thread slept for 5.437562 ms
    The thread slept for 6.064458 ms
    The thread slept for 5.674744 ms
    The thread slept for 15.354466 ms
    The thread slept for 5.869461 ms
    The thread slept for 5.785372 ms
    The thread slept for 5.804649 ms
    If you really need a precise timer you need either a real-time OS or a different solution, the method sleep(millis, nanos) will solve the problem without proper OS/hardware

  • So I have an I Pad that will not charge. This is the second time that this situation has occurred the first time it was covered under warranty (But not this time). So they offered me a new old one for $250.00 and 90 day warranty. Seems like the life if th

    Any thoughts about my second go around with an I pad that will not charge. This is second go around and I'm wondering if I should repalce or opt out and go different route ???? Can not imagin that Apple could give the type of support  I'm recieving and continue?? The first one was under warranty not so lucky this time.

    Go to the Apple Store and try a different charger & cable.
    The quickest way (and really the only way) to charge your iPad is with the included 10W USB Power Adapter. iPad will also charge, although more slowly, when attached to a computer with a high-power USB port (many recent Mac computers) or with an iPhone Power Adapter (5W). When attached to a computer via a standard USB port (most PCs or older Mac computers) iPad will charge very slowly (but iPad indicates not charging). Make sure your computer is on while charging iPad via USB. If iPad is connected to a computer that’s turned off or is in sleep or standby mode, the iPad battery will continue to drain.
    Apple recommends that once a month you let the iPad fully discharge & then recharge to 100%.
    How to Calibrate Your Mac, iPhone, or iPad Battery
    http://www.macblend.com/how-to-calibrate-your-mac-iphone-or-ipad-battery/
    At this link http://www.tomshardware.com/reviews/galaxy-tab-android-tablet,3014-11.html , tests show that the iPad 2 battery (25 watt-hours) will charge to 90% in 3 hours 1 minute. It will charge to 100% in 4 hours 2 minutes. The new iPad has a larger capacity battery (42 watt-hours), so using the 10W charger will obviously take longer. If you are using your iPad while charging, it will take even longer. It's best to turn your new iPad OFF and charge over night. Also look at The iPad's charging challenge explained http://www.macworld.com/article/1150356/ipadcharging.html
    Also, if you have a 3rd generation iPad, look at
    Apple: iPad Battery Nothing to Get Charged Up About
    http://allthingsd.com/20120327/apple-ipad-battery-nothing-to-get-charged-up-abou t/
    Apple Explains New iPad's Continued Charging Beyond 100% Battery Level
    http://www.macrumors.com/2012/03/27/apple-explains-new-ipads-continued-charging- beyond-100-battery-level/
    New iPad Takes Much Longer to Charge Than iPad 2
    http://www.iphonehacks.com/2012/03/new-ipad-takes-much-longer-to-charge-than-ipa d-2.html
    Apple Batteries - iPad http://www.apple.com/batteries/ipad.html
    Extend iPad Battery Life (Look at pjl123 comment)
    https://discussions.apple.com/thread/3921324?tstart=30
    New iPad Slow to Recharge, Barely Charges During Use
    http://www.pcworld.com/article/252326/new_ipad_slow_to_recharge_barely_charges_d uring_use.html
    Tips About Charging for New iPad 3
    http://goodscool-electronics.blogspot.com/2012/04/tips-about-charging-for-new-ip ad-3.html
    Prolong battery lifespan for iPad / iPad 2 / iPad 3: charging tips
    http://thehowto.wikidot.com/prolong-battery-lifespan-for-ipad
    iPhone, iPod, Using the iPad Charger
    http://support.apple.com/kb/HT4327
    Install and use Battery Doctor HD
    http://itunes.apple.com/tw/app/battery-doctor-hd/id459702901?mt=8
    In rare instances when using the Camera Connection Kit, you may notice that iPad does not charge after using the Camera Connection Kit. Disconnecting and reconnecting the iPad from the charger will resolve this issue.
     Cheers, Tom

  • Hi,  If I have 1 license for creative cloud, will it possible to install in 2 computers (1 laptop and 1 desktop)?  When I am in the office I can use desktop and at home I can use laptop? At the same time I will be using only one devise. Will that be possi

    Hi,  If I have 1 license for creative cloud, will it possible to install in 2 computers (1 laptop and 1 desktop)?  When I am in the office I can use desktop and at home I can use laptop? At the same time I will be using only one devise. Will that be possible?  Thanks

    Yes. Yes. Yes.
    Mylenium

  • How come whenever i plug my iPhone 5 into the computer the device will not show up on my itunes.  This is the first time that i have done it since i updated to iOS7 and before i had no problem but now it just wont work.

    How come whenever i plug my iPhone 5 into the computer the device will not show up on my itunes.  This is the first time that i have done it since i updated to iOS7 and before i had no problem but now it just wont work.

    Hi Celia51510,
    Welcome to the Support Communities!
    The article below may be able to help you with this issue.
    Click on the link to see more details and screenshots. 
    I can't tell from your post if you are using a Windows or a Mac Computer.
    Try deleting the iTunes application and redownloading the version you need below:
    iTunes 11.1 Download for Mac
    http://support.apple.com/kb/DL1614
    iTunes 11.1 for Windows (64-bit)
    http://support.apple.com/kb/DL1615
    Cheers,
    - Judy

  • I am trying to create a button in flash that will display 4 separate images at the same time when clicked.  I can't get the images to stay on when I take the mouse of the button.  I need the actions script code to make this happen.

    I am trying to create a button in flash that will allow the user to click on the button and 4 separate images show up at the same time.  I can get the images to appear when I click the button but they will not stay on the screen.  I need to know what code I use to make the images stay once the button is clicked, then I need to know exactly where I place that code.  It does not appear to be possible to add the action code to the buttons layer since each time I add a new layer I just get another "up" "over" "down" and "hit" line.
    Thank you in advance
    AP

    It is not clear how you are trying to realize this from your description.  If you are trying to create this within a button symbol it will not work.  Explain your approach and if there is code involved, show what you have so far.

  • Report Manager taking a long time to publish with Content Set that will pro

    Hi I am trying to publish 2 reports in report manager that each have multiple tabs. The are Exprense and Revenue Trend reports that will publish for each balancing segment, one years previous data. I can publish in pdf and html however not very pretty. Excel is taking too long and eventually crashed my session. Does anyone have any info on excel performance issues: The compents of teach FSG are as follows:
    Row Set
    Column Set
    Content set ( this provides the blanacing segment)
    Row Order
    Please help not long before go live.
    Thanks

    Please post the details of the application release, database version and OS.
    Please see these docs.
    Report Manager Taking Long Time To Produce Output In Excel. Flickering Occurs When the Output of an FSG Report data Being Populated In Excel. [ID 949300.1]
    Report Manager - Master Note [ID 726774.1]
    Poor Performance In HTML Due To FO Generator [ID 827288.1]
    Report Manager Troubleshooting [ID 858505.1]
    Thanks,
    Hussein

  • Please help block my ipod touch second generation and forget the code, try putting the code so many times that now says connect to itunes, I connect but will not let me do anything that tells me this should unlock with key and I should do for Please help!

    please helpme i block my ipod touch second generation and forget the code, try putting the code so many times that now says connect to itunes, I connect but will not let me do anything that tells me this  should unlock with key and I should do for Please help!. thanks

    Place the iPOd in recovery mode and then restore. For recovery mode:
    iPhone and iPod touch: Unable to update or restore

  • I have question about hooking up an external hdd to a time capsule and still have my printer hooked up as well. Anyone got any tips for me, how to do it and what brand of harddrive that will work best for me 1 or 2 TB

    i have question about hooking up an external hdd to a time capsule and still have my printer hooked up as well. Anyone got any tips for me, how to do it and what brand of harddrive that will work best for me 1 or 2 TB

    You just need a powered hub.. if you already use one then fine.
    Plug in just about any external hard disk will work fine. Format has to be readable by the TC.. ie fat32.. or much better HFS+.. plug it into a Mac to prepare the drive.
    Pick whatever size suits.. nowadays 2TB are most economical.
    WD, Seagate have goobled up all the minor players.. so pick one.
    Whatever suits your budget and asthetics.
    NOTE.. The USB on the TC is fine for printers.. IMHO it is the wrong way to go with USB disks.. use the internal disk of the TC.. USB is less than half the native speed plugged into a Mac.. TC to USB is slow.. far slower than internal drive.. or using external drive as external.

  • How do I write a vi that will save graph data and text data (related to the graph) so the next time I want to view the graph data the text data is included in the read vi?

    I am new at writing vi's and hope you may be able to help. I would like to create a vi that will graph measurements taken from a daq device. I would like to include text data that a user can choose from (example: machine number, test circuit, load cell type) that will stay with the graph so when the graph is viewed at a later time the text data (explaining parts of the graph) will display with the graph data. I have included a vi I am using to capture and display a force value. Any help would be greatly appreicated.
    Attachments:
    force.vi ‏500 KB

    What you want is a DATALOG file:
    When you save a file, use the BUNDLE function to bundle your machine number, test circuit, whatever (include a few spare fields), plus your graph data. Get the graph data from the source, or use a local variable of the graph itself.
    Wire the bundle output to the DATALOG TYPE of a NEW FILE function. (I presume you'll use a FILE DIALOG set to SAVE FILE to choose a file path).
    Write the same bundle output to the DATA input of a WRITE FILE function.
    Use a CLOSE FILE function to (ahem) close the file.
    When you want to read a file, use a FILE DIALOG set to EXISTING FILE (or some other means) to specify what file to read. Wire the same cluster type to the DATALOG TYPE of the FILE DIALOG, so that it will only
    offer files of the correct type.
    When you have a file path chosen, wire the bundle to the DATALOG TYPE input of a FILE OPEN operation.
    Use a FILE READ to read a single cluster - the output of FILE READ will be a cluster of the right type.
    Use a CLOSE FILE function to....
    Out of the FILE READ function, you can UNBUNDLE BY NAME the data and send to the graph and the other fields, or, if you're clever, you can use a cluster on the screen, and not unbundle it. That's harder though, since you probably want the text fields to be controls (inputs) and the graph to be an indicator (output).
    Hope that helps.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • Is there an iCal add-in that will accommodate different time zones?

    I am a former Windows/Outlook guy, now living in an all-Apple world (iMac on my desktop; iPhone, iPad and/or MacBook Air when I travel, which I frequently do.)
    Here is my challenge (something that was easy, easy, easy to do in Outlook): 
    I want to be able to create events in iCal that will occur in some other time zone without having to do the mental math. 
    For example, I am sitting at my desk in my home time zone (Eastern Time) and book a flight from Washington to Los Angeles for sometime next month.  What I WANT to do is create an event with a start time of 8:30 am Eastern and an end time of 11:30 am Pacific.  To do that now, I have to mentally say "That's really 8:30 Eastern to 2:30 pm Eastern". Hope I got the conversion right.  If I did, all is good.  The event will show up properly in my iPhone at departure time in DC.  When I fire up my iPhone on landing in LA, the internal clock adjusts, and everything is good. If I make a mental mistake (for example, add hours rather than subtract), I might miss my flight.
    I have another trip already on the books to Dallas.  I get an email from a colleague setting up a meeting while I am there.  Regardless of whether I am sitting at my iMac in DC or looking at my MacBook in a hotel room in LA, what I want to is be able to enter the appointment as "2 o'clock Central Time" and be assured it will show up in the proper time in my calendar, regardless of where (or when) in the world I happen to be the next time I look at iCal.
    Most of the comments on this forum suggest work arounds. "Just work it out in your head". But I am not talking about doing this occasionally with one or two events.  I do it constantly with literally scores of events occuring in multiple time zones. And there is nothing worse than setting an alarm clock for 3 in the morning in Paris so you can get up to catch that 8 pm Eastern board of directors conference call only to discover you missed the call because you screwed up the math when you entered the call in your calendar.
    Like I said. Outlook in Windows does this flawlessly.  But setting up Outlook on my home Mac (in a Windows partition) defeats the purpose of my trying to do it on the software, platform and hardware I prefer to use.
    Which is a long winded explanation to get back to my simple question:  is there an iCal add-in or standalone app that plays well with iCal that will let me designate the time zone for start and end times when I create an iCal entry?

    It sounds like 1Password may do what you're looking for.
    https://itunes.apple.com/us/app/1password-password-manager/id568903335?mt=8

  • I am looking for an iPad App that will play a specific iTunes song, at a specific time, on a specific day?  Thank you all!

    i am looking for an iPad App that will play a specific iTunes song, at a specific time, on a specific day?  Thank you all!

    Sorry, i did not say that i need to go out further than 1 week.  This is for a church Bell Tower Music System.  So we don't want to have to re program the music every week.  We are looking for more of a Calender App that will play iTunes Songs for alarms...different songs, on different days.  IDEAS ANYONE ???

Maybe you are looking for

  • Selling old iPhone 3g - erased, removed sim questions for new buyer

    I have an old 3g that we have service turned off on, i did the erase all content thing and removed the sim, phone restared and said I needed to hook it up to itunes and it needed the sim againput the sim back in, got the phone back to what looks like

  • Tax and tolerance

    hi, 1) what actually is account key in the context of tax. where to define it? 2) what is this tolerance group? tolerance group for gl accounts clearing acc (external procurement) clearing acc (in house production) thanks

  • Using Managed bean

    Hi All, How to use managed bean instead of backing bean to retreive a value from a object. a)Say in my form i have selectoneChoice box and i need to retreive the value inputed by the user b)According to the value selected by the user i need to show a

  • Help using afconvert in terminal

    I'm trying to use afconvert to convert an ac3 file in to an aac file. And I'm getting no where here is how far I've got. MacBook:~ B4tm4n$ afconvert -v -f mp4f -d aac -b 128000 /Users/B4tm4n/Desktop/\[mkvextract\]/audio2.ac3 Input file: audio2.ac3, 0

  • Playlist folder "no songs"

    While viewing playlist folders in iPod Touch, the top level playlist folders show "no songs' in the summary line immediately below the folder name. In my setup these are container folders only, i.e., "70s" contains smart playlists for 1970, 1971, 197