Looping a method every 1/4 second

I need to write a method that will loop another method
every 1/4 second. I'm not sure what syntax to use to make
it work with time. Can someone give me input? Thanks.

Have u looked at timers. There's
java.util.Timer;
and
javax.swing.Timer;
http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
http://java.sun.com/products/jfc/tsc/articles/timer/
I did something like this to run a method every seconds in a app im making.
//Swing timer
Timer timer = new Timer(1000, new TimerListener()); //run every second
// This runs TimerListener() method every second after i call timer.start()
class TimerListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {
if(whatever ur checking){
//bla blah
else{
timer.stop();
// clean up ...
If its not gui the tut suggest to use java.util.Timer;
http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
hth

Similar Messages

  • Looping a method

    Is there anyway to loop a method every hour or so? to where it doesnt eat up ram or cpu

    Not sure I understand your request, maybe the following links can help:
    * http://java.sun.com/javase/6/docs/api/java/util/Timer.html
    * http://www.exampledepot.com/egs/java.util/ScheduleRepeat.html
    Luck,
    CJSL

  • Run method every X seconds

    Hi all,
    I have a method that I would like to run every 200ms from a JSP page. I figured this was more related to Java programming than JSP, so I'm posting here. Let me explain why.
    I have an application that captures a still image in the form of a byte[] from a video camera (capturing the video feed is not an option; it can only capture a still image from the camera). I then convert the byte[] to an RGB image and display that image on a webpage using JSP. I would like this image to be updated on the JSP page at a frequency of 5Hz, or 200ms. To do so this, I figured I'd need to call my getRGBImage() method every 200ms and consequently call the ImageIO.write(...) method. This brings me to some questions.
    1) Can this even be done? Is 5Hz too fast for all of this to execute?
    2) If this can be done, how would I go about doing this? Is there a better way than calling a method every 200ms? Should I use Timer? If so, how would I use it? I read the API, but I don't see how I can apply it.
    If I need to post any code or whatever, please let me know.
    Thanks,
    Dan

    Yeah, you would use the Timer in the applet. I assume
    the applet would need to connect to the server and
    get the latest version of the image at each tick of
    the timer.I can have an ongoing connection with the server, I just need to call the method to retrieve the image data multiple times. The server provides me with a method, imageAcquisition, that I call with
    byte[] in = imAq.imageAcquisition; //imAq is the server proxyTherefore, I shouldn't need to initialize a connection to the server every time I want to retrieve the image data.
    Anyway, that solves my general problem, so any more-specific problems related to applets/timers/etc I'll put in a new thread.
    Thanks again,
    Dan

  • My Radio on my Nano won't pick up a signal.. I cennected my headphones and am in the middle of the city. Also my iPod keeps pausing every like 30 seconds.. What do I do?

    My Radio on my Nano won't pick up a signal.. I cennected my headphones and am in the middle of the city, so there are plenty of stations to find. Also my iPod keeps pausing every like 30 seconds when I try to listen to my music. I just got it for Christmas and already loaded it with songs.. What do I do?

    Push the headphone jack all the way in, you don't have it fully plugged in yet.

  • When  i play a song from my itunes library, there is a short "buzzing" sound about every 20-30 seconds. I had the problem before and thought it was fixed after verifying that itunes was my default player. Any ideas to fix the problem now??

    when i play a song from my itunes library, there is a short "buzzing" sound about every 20-30 seconds. This same thing happened some time ago, and i thought i had it sovled by verifying that itunes was my default player. Howerver, it has started up again. Any ideas how to fix the problem??

    I am having the same problem I have over 11.5 GB of .tmp files, many 1000s. Here is a thread I have found with some more info:
    http://discussions.apple.com/thread.jspa?messageID=824308
    That thread is almost a year old so I'm not holding out hope for a fix from apple. I'm going to try deleting them and see how it goes...

  • IPod Mini continually skips tracks all the time every half a second!

    My iPod Mini continually skips tracks all the time every half a second. The only thing that stops it is if you press pause but once you press play off it goes again. This means noi music is able to be played because it's always skipping. The menu button works as does the backlight if you hold the menu button down. The enter button works and the touch pad navigation also works. Both skip buttons have no effect on the unstoppable skipping. Can anybody help or at least verify the problem with other users of simular problems and if they were able to fix them simply, without having to go to an Apple dealer (it's out of warrenty i think)Any help would be appreciated.

    My iPod Mini continually skips tracks all the time
    every half a second. The only thing that stops it is
    if you press pause but once you press play off it
    goes again. This means noi music is able to be played
    because it's always skipping. The menu button works
    as does the backlight if you hold the menu button
    down. The enter button works and the touch pad
    navigation also works. Both skip buttons have no
    effect on the unstoppable skipping. Can anybody help
    or at least verify the problem with other users of
    simular problems and if they were able to fix them
    simply, without having to go to an Apple dealer (it's
    out of warrenty i think)Any help would be appreciated.
    ---thats what happened to mine, then it stopped working altogether. liek not playing songs at ALL. i have tryed reformating it, i finally got all the settings erased, but then it woulndt 'talk' to iTunes. it has been about 2 months and im still working on it. my suggestion is send it in beore it gets as bad as mine.
    good luck!
    -adair
    no idea 1123   Windows XP   haha
      Windows XP  

  • Airtunes drops out every 15-30 seconds?

    Any advice?
    As of yesterday, my airport express connected to my stereo stops playing music every 15-30 seconds.
    Very annoying!
    Did a factory reset and still having the problem.
    Any hints?

    Sorted itself out after software upgrades at a later date

  • Mouse pauses every 2.5 seconds

    Got a brand new 27 inch 3.06 Ghz Core 2 Duo iMac (2009). The magic mouse AND any USB mouse that I plug into it pauses at the same interval about every 2.5 seconds. It's just enough to screw up everything you are trying to do.
    Tinkering with it, I have managed to figure out that it only does it when I use an external monitor plugged into the iMac...
    I have an external 24 inch monitor plugged into the iMac to extend my desktop. The external monitor has 2 inputs (DVI and VGA). When I have both the iMac and the 24 inch monitor set to Mac (DVI), the mouse works just fine. But when the external monitor is set on the Windows machine (VGA), the mac mouse (Magic mouse or USB mouse) pauses every 2.5 seconds. I don't know why monitor input settings would cause the mouse to pause and I haven't seen any threads with the same problem. Any ideas?

    The 27-inch iMac is the first (and only) Mac to make double-use of its video port.
    I think you have already shown it is somehow related to the Mini DisplayPort, and you can easily reproduce the problem on-demand. Since Mac OS X still sees the second display, even when it is switched over to the VGA input, it may not be related to the new video input capability.
    As a test, what happens if you put it into the state where the pausing is going on, then disconnect the adapter on the back of the iMac. I would assume iMac would pause for a second and reset to having only its built-in display, and the ongoing pausing issue would stop. Then, reconnect the adapter (display still set to VGA with active input). The iMac should reset to having the external display. Does the pausing issue start happening again?
    Here's another test. With the display set to DVI, insert the Mac OS X installation disc and restart with the C key held down. This will force start up from the optical drive. When you get to Installer, you should see the default Desktop background on the external display, and that will indicate it is being recognized and used. You should be able to move your mouse cursor onto it, although the arrangement may be different. Now, do the thing that usually causes the pausing. When you are started up from a different system, does the pausing still occur?

  • Why does my screen flicker every 10-15 seconds?

    Why does my screen flicker every 10-15 seconds?

    like a blinking? do you have the late 08 MBP?
    if so go to system, energy saver, and select better performance. Your screen should be flicker free.

  • Looping over method which returns a query

    HI,
    I have a method that returns a query, I pass into this method
    a ID number, which the query uses in the where clause. Now I have
    another query which returns a list of ID numbers that I loop
    through calling the first method and passing in the ID number, for
    example
    methodA
    loop through methodA results
    call methodB passing in methodA.ID
    get results from methodB
    close loop
    now the problem I'm having is that methodB returns a query
    and I want to be able to return the results from methodB as one
    single query structure. I'm not sure how many times I will loop
    through the results from methodA, it could be twice, it could by
    ten time. So the results from calling methodB could be very large.
    How can I add the results from methodB into one single query
    structure?

    how about creating an empty query with cfset newQuery =
    QueryNew([list of columns]);
    and then on each loop through method B add a new row to this
    new query, and then return that query as result?

  • Facebook keep loading every 2 - 3 seconds while scrolling down... It is very frustrating.. I like new firefox but this should be fixed...

    I liked new firefox... I made it my default browser..But I am very frustrated with issue here I mentioned. Whenever I scroll down on facebook.. every 2-3 seconds page gets loading and it eventually make my surfing experience bad... I want you to fix that issue as soon as possible and then only I will start again firefox. So, just let me know when you make fix....

    Hello,
    Many site issues can be caused by corrupt cookies or cache. In order to try to fix these problems, the first step is to clear both cookies and the cache.
    Note: ''This will temporarily log you out of all sites you're logged in to.''
    To clear cache and cookies do the following:
    #Go to Firefox > History > Clear recent history or (if no Firefox button is shown) go to Tools > Clear recent history.
    #Under "Time range to clear", select "Everything".
    #Now, click the arrow next to Details to toggle the Details list active.
    #From the details list, check ''Cache'' and ''Cookies'' and uncheck everything else.
    #Now click the ''Clear now'' button.
    Further information can be found in the [[Clear your cache, history and other personal information in Firefox]] article.
    Did this fix your problems? Please report back to us!
    Thank you.

  • Firefox v15 and up cause my computer (MAC OSX 10.8.2) to freeze for about 30 seconds every 15-30 seconds and forces me to turn it off with the power button

    Firefox v15 and up cause my computer (MAC OSX 10.8.2) to freeze for about 30 seconds every 15-30 seconds and forces me to turn it off with the power button. It only causes this after I have opened Firefox, my computer runs fine before opening Firefox. I have uninstalled Firefox and cleared my personal settings. I have installed future updates (16 and 17) and have run into the same issue. I cannot pull any information on RAM or CPU usage because when it happens it makes my computer unusable. Unfortunately I need to use FF for work and can't. I have tried the different responses on the forums to reduce the amount of RAM and CPU usage with no change in performance.

    Duplicate of https://support.mozilla.org/en-US/questions/944207

  • July 2011 15" macbook pro now freezing temporairly every 10-15 seconds

    I'm having an issue with my summer 2011 macbook pro 15".
    typing, web browsing etc.. every 10-15 seconds the whole computer freezes for about 5 seconds then repeats.  it's really annoying to use this way.  it affects all functions.

    Hi...
    How much free space on the startup disk?
    Right or control click the MacintoshHD icon on your Desktop. Click Get Info. In the Get Info window you will see Capacity and Available. Make sure there's a minimum of 15% free disk space.
    If there's enough free storage space on the disk, try Starting up in Safe Mode
    A Safe Mode boot takes much longer than a normal boot so be patient. Once you see the Desktop, click the Apple menu icon top left in the screen. From the drop down menu click Restart.
    If the drive still freezes after booting in Safe Mode, since you are running v10.7.4 Lion, use Lion Recovery  to repair the startup disk or reinstall the Mac OS X.
    edited by:  cs

  • Every time I use the internet the pages keep reloading every 10-20 seconds. worked with my internet provider for over a year thinking it was their fault, but it turns out it's my computer. Can anybody help? Thanks.

    Every time I'm using the internet, my pages reload every 10-20 seconds. Very aggravating. I worked with my internet provider for a year thinking it was their fault, but it turns out to be my computer, not the internet provider. Can anybody tell me why this is happening? Thank you.

    Hi Mary,
    Open Console in Applications>Utilities & see if there are any clues or repeating messages when this happens.

  • Why does my ipod keep disconnecting and connecting every half a second?

    I had my iPod touch (4th gen, ios6) synced to a desktop and when I tried connecting it to my new laptop to sync it keeps connecting then disconnecting every half a second (flashing on and off) and will not connect at all. Do I need to do something with my old computer? I don't think it's something wrong with the cord because it connects to the wall just fine.

    Different conductors/contacts are used for charging and dats. Thus, it still could be a bad cable.
    - Reset the iOS device. Nothing will be lost      
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reboot the computer
    - Try another USB port and cable
    - Iphone 5 lightning port charging problem - SOLUTION!
    - Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
    - Reset all settings                 
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Try on another computer to help determine if iPod or computer problem
    - If it works with other computer that indicates a problem with your computer. Try
    Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP
    or              
    Removing and reinstalling iTunes and other software components for Windows Vista, Windows 7, or Windows 8
    - Restore from backup. See:                                               
    iOS: Back up and restore your iOS device with iCloud or iTunes
    - Restore to factory settings/new iOS device.                       
    If still problem with all compouters, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar                                                              

Maybe you are looking for