Pause for x seconds, how to?

Hi,
I wanna write a routine that invokes an action every 2 seconds, is there a command like wait(2 seconds) or something similar in java?

> I wanna write a routine that invokes an action every 2
seconds, is there a command like wait(2 seconds) or
something similar in java?
You've actually described two different things...
Someone's already given the way to pause the current thread for a certain amount of time.
But if you really want to do something every few seconds, you might look into Threads and/or Timers. Sure, you could just have a loop somewhere in your app that...
(1) Does useful stuff,
(2) Waits for a few seconds,
(3) Rinse and repeat...
but if you're using AWT and/or Swing, you may find that your GUI stops updating during your pauses, which might be annoying.
Here's a little snippet you can add to a basic Swing app to see a very simple example of a Timer making a button flash...
    // ... other stuff ...
    private JButton exitButton = new JButton();
    private Timer exitButtonTimer = new Timer(250, new ActionListener()
        public void actionPerformed(ActionEvent ae)
            Color bg = exitButton.getBackground();
            Color fg = exitButton.getForeground();
            exitButton.setBackground(fg);
            exitButton.setForeground(bg);
    // then wherever you initialize your Swing components,
    // do this...
        exitButtonTimer.start();

Similar Messages

  • Videos and gifs sometime pause for a second, need to tweak performance

    I have a high end gaming laptop with 16GB ram, 4th gen i7, SSD hard drive, NVIDIA 770m graphics.
    When I have a lot of tabs open, Firefox slows down a lot. Sometime animated gifs pause until I move my mouse, sometimes videos on various sites pause for a second (audio keeps going) and then catches up to the audio. The video issue happens on multiple sites including youtube.
    I have updated flash, java, video drivers, windows updates, etc. I have an onboard intel 4600 video card which was being used for firefox. I switched to the NVIDIA card and I still have the same issues.
    My computer should have the power to handle what I'm viewing. How can I tweak my settings to allow firefox to use more resources if needed? In task manager it never seems to get above 1GB Ram and 24% processor, yet still looks laggy as if my system is out of resources.
    If it's important, I seem to get the same type of lag in regular internet explorer....
    thanks

    You can check if there is an update for your graphics display driver.
    *https://support.mozilla.org/kb/how-do-i-upgrade-my-graphics-drivers
    You can try to disable hardware acceleration in Firefox.
    *Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    You need to close and restart Firefox after toggling this setting.
    Also check for issues caused by extensions.
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    *https://support.mozilla.org/kb/upgrade-graphics-drivers-use-hardware-acceleration

  • Does anyone has the same scrolling problem? My macbook air 13''(2010) running lion, when files in a folder arranged by kind, every scrolling paused for a second..?

    does anyone has the same scrolling problem? My macbook air 13''(2010) running lion, when files in a folder arranged by kind, every scrolling paused for a second..?

    does anyone has the same scrolling problem? My macbook air 13''(2010) running lion, when files in a folder arranged by kind, every scrolling paused for a second..?

  • Finger sensor not working and some time iphone 6 screen also hang/pause  for few seconds

    In my iphone6 finger sensor not working and some time iphone 6 screen also hang/pause  for few seconds.

    Try cleaning the sensor, remove all fingerprints from the settings, and the start over in recognizing prints. There are a number of things that make prints hard to read, sweat, lotion, dirty hands, etc.

  • Laptop pauses for few seconds fequently

    My laptop pauses for few seconds every  2-3  minutes . And this happens after around 15 minutes use of my laptop.  What could be the problem?

    Binita,
    Welcome to the HP Community Forum.
    Could be almost anything:
    A program might running 'round in circles and slowing eating up all your memory is one guess.
    Your system could be in need of maintenance -- the disk might be badly fragmented:  Your files might be spread all over the place -- and in pieces -- and far away from each other.  This is relative, of course.  The "far away" is tiny distances and the amount of time it takes your computer to gather data is tiny amounts of time -- but it can add up to big delays after awhile -- delays that you notice.
    Your computer might just have too many junk files that are "getting in the way" of a clean operation.
    Your computer might have little bitty mistakes in the File System that are making it hard for the computer to perform its tasks.  Tech speak for File System Errors.
    It could be a network problem, although this is something you will have to track.  The fact that the issue starts after you have been on the system for awhile means you need to know what you are doing during the slow-down to have an idea what you are looking for.  The Task Manager can give you an idea whether the Network traffic is heavy and the Performance Monitor can help track traffic hogs.
    Could be your Internet Service Provider dragging down your service -- this is harder to track, this is outside of the purview of this forum, and this is not an HP problem although you will find lots of people swearing that ISP issues come back to the computer being the culprit.  If you are streaming, gaming, or using the system for anything that your ISP dislikes, it may put a choke on your service after a specified time.
    Could be malware -- This is a different arena and you need to look to your Security Software to see if there are issues there.  Run a deep scan to be sure the system is clean.
    You might take a look at the following and follow at least some of the suggestions:
    Improving System Performance without Adding Memory (Windows 8)
    Click the Kudos Thumbs-Up to say Thank You!
    And...Click Accept as Solution when my Answer provides a Fix or Workaround!
    I am pleased to provide assistance on behalf of HP. I do not work for HP. 
    Kind Regards,
    Dragon-Fur

  • Chapter markers created in DVD Studio Pro pause for a second on playback.

    I have been using the FCP suite for quite some time and we author a lot of DVD's in DVD Studio Pro. We produce many DVD's which require chapter breaks. My problem is that, when the DVD's we produce are played back, on most players the DVD will pause for a second or so on each chapter break/marker. Is there a way to get around this problem? The playback of the DVD's is fine, but the pauses at every chapter break/marker are annoying for us & our clients.

    Hi Nat
    It sounds like you're setting each chapter marker to end jump to the next. This will cause the pause you describe - if you leave each chapter as 'not set' you should be able to play thru them no problem.
    Cheers
    B

  • EJB thread pausing for 28 seconds

    We have a weblogic application running with a JDMK package to receive and process SNMP packets. This processor is running on a separate thread off a EJB. We just recently encountered an issue where after processing several packets the thread pauses in the middle of processing for about 28 seconds, then continues processing again for a second and pauses again. This keeps occurring. Note the times vary and the pause spot in the processing can also vary.
    Moreover, depending on what Linux system weblogic is running on, the problem may go away. In all cases the Linux systems never get more than 20% busy by CPU time.
    Any thoughts?

    Turns out the issue was related to OS level SNMP port IO timeout. There were routing issues causing DNS lookups a long time to resolve. This in-turn caused delays up to 28+ seconds in the JDMK SNMP manager during some snmpGet of OIDs and MIB tables. Since the same JDMK SNMP manager is used from trap recipient and listener it also caused delays in processing traps. We solved the issue by updating the resolv.conf to something that worked. This was verified using nslookup and traceroute commands on Linux.

  • Making music videos, QuickTime Pro likes to pause for a second.

    I'm making music videos, and some times at the start of the video, or where I add other video to the .mov file, the video likes to pause for 1/4th to a second, then the video like jerks forward to where it should be, while the audio is playing the way it should.
    Is there any way to keep this from occuring?
    Example (3 megs.)

    Your data rate for the video is 4.5 times of what it should be (9240 kbits/s). Try using 2000 kbits/s for the video data rate.
    Here are some other factors that can make the video sluggest along with the above:
    1) The dimensions of the video is 849x406. The height and width of the video should be divisible by, 16 for best... or 8 for better... or 4 for good. This can effect the encoding (always does) or playback of the video.
    Here read this article: http://www.adobe.com/devnet/flash/apps/flvbitrate_calculator/videosizes.html
    Even tho the above article is for Flash it also applies to h.264.
    2) The audio is mp3, this isn't h.264 complient. AAC audio is... I would change the audio encoding to AAC.
    3) And lastly...what program did you use to encode this video with?
    I'm glade you supplied a short video. Most people don't. See if next time you can supply at least ten seconds. Thirty second would be the bomb!
    I took your video and copy/pasted it to lengthen it to 13 seconds. Encoded with Apple's Compressor...h.264....2000 kbits/s...audio ACC 128 kbits/s... dimensions 848x400
    http://www.setfreedenver.org/DemoA/pause_demoA.html
    There still is some jerkiness. This is inherent from the footage you supplied.

  • Classic 160 pauses for two seconds during playback of applelossless content

    I have a problem with my new Classic, when playing back apple lossless content I occasionally get a 2 second pause. The really odd thing is it also does it when connected to my alpine ida-x001, which does not use the Ipod to play the file, it only reads it from the disk. Anyone else seen this problem?

    Yes, I have seen that too, and I'm using lossless as well. Just posted about it in another topic (http://discussions.apple.com/thread.jspa?threadID=1135545). I'll repeat it here (just to confuse the search engine):
    My 160Gb (I upgraded it to 1.0.1 on first connection to iTunes) skips parts of songs too. It will play properly for 30 to 60 minutes and then sometimes it stops for 2 seconds in the middle of a track and then continues or jumps to the next track.
    I did notice that when it does this, the volume bar shows up. Perhaps it's a faulty click wheel that does something without me touching it? I'm going to change it today.

  • What command to use to "pause for 5 seconds"?

    Hi, I just want to find a command in Java that will pause the swing program for 5 seconds or something?
    Thanks in advance.

    When putting a thread to sleep for 5 seconds you should use Thread.sleep(5000) - don't call getCurentThread() as sleep is a static method, so you'd just be making your code look confusing to others and adding unnecessary overhead at runtime.

  • Music pauses for a second

    When I have music playing and I either click the lock button or enter or exit the Music app, the music will stop playing for a second, then start again. This isn't a problem per se, but it is rather annoying. It hadn't done this with iOS 3.

    I have the exact same problem. It is annoying since it never happened with the OS3.
    Could it be a bug?

  • Notification "install downloaded upgrade 4.1 " came up for 1 second. how do I do so ?

    pop-up, lower right,"install downloaded upgrade Firefox 4.1" for 1 second. not in downloads . what now ?

    It should automatically install when you restart Firefox. If that does not happen, in the Help menu select "About Firefox", that will allow you to check for updates again.

  • Mac Pro shows beach ball and pauses for several seconds

    I have an issue with my new Mac Pro (2013) wherein I can be running nothing but Pages for instance (does same with other non-graphic intense programs as well) and I will get a beach ball, then the computer will halt for several seconds until the beachball clears.  Why is this happening?  I have 500 GB SSD and 16 GB Apple memory.   This happens also when bouncing a two or three instrument song in Logic Pro.  Anyone know of issues?

    When you see a beachball cursor or the slowness is especially bad, note the exact time: hour, minute, second.  
    These instructions must be carried out as an administrator. If you have only one user account, you are the administrator.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad and start typing the name.
    The title of the Console window should be All Messages. If it isn't, select
              SYSTEM LOG QUERIES ▹ All Messages
    from the log list on the left. If you don't see that list, select
              View ▹ Show Log List
    from the menu bar at the top of the screen.
    Each message in the log begins with the date and time when it was entered. Scroll back to the time you noted above.
    Select the messages entered from then until the end of the episode, or until they start to repeat, whichever comes first.
    Copy the messages to the Clipboard by pressing the key combination command-C. Paste into a reply to this message by pressing command-V.
    The log contains a vast amount of information, almost all of it useless for solving any particular problem. When posting a log extract, be selective. A few dozen lines are almost always more than enough.
    Please don't indiscriminately dump thousands of lines from the log into this discussion.
    Please don't post screenshots of log messages—post the text.
    Some private information, such as your name, may appear in the log. Anonymize before posting.

  • Non-blocking sockets operation, block/pausing for milli-seconds at a time.

    The stack trace is always as follows. This operation can block for 1.0 to 2.1 ms approx once every 3 minutes, sometimes a second apart or not at all for 8 minutes. Have Java 6 update 18 on Centos 5.3. The server is lightly loaded.
            at sun.nio.ch.NativeThread.current(Native Method)
            at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:182)Looking at what this function does, its not clear why it should block/pause or how to fix it.
    Any suggestions welcome.

    I would try running with hotspot disabled
    in case something is optimized away
    and you are actually blocked on some lock
    and it only looks like you are blocked on NativeTread.current().

  • After Effects pausing for a second before playback

    Once a prerender has completed after effects takes a second to start the visual playback. VO starts straight away. This corrects itself once the timeline has completely played through and starts from the start.
    Any ideas?

    As Rick says, this is a known bug with Mac OSX v10.10 (Yosemite).
    See this:
    After Effects with Mac OSX v10.10 (Yosemite)

Maybe you are looking for

  • Alpha channel export question

    I have an editor that keyed the green screen out of some footage but because we're having a problem settling on a background (we're in different locations) I just want him to send me the keyed footage with the black transparent background so I can do

  • [PS CS5] Type tool-related crash.

    The Checklist: Photoshop CS5 12.0.4 x64 running on a Windows 7 x64 SP1 machine, with 8 GBs of RAM, plenty HD space on both drives (174GB free on C, 321GB free on D), no related software interferring with Photoshop that I know off, besides an Intuos 4

  • Problem displaying table generated by jsp

    Hi! I�m trying to build a dynamic form by calling different servlets from my jsp-page. Somthing goes wrong however, the first <select> generates another <select>, but when the second generates the third, the second <select>-table is overwritten. Why?

  • CS5 dodge and burn overkill

    I don't know if anyone else has this problem but, since upgrading from CS4 to CS5 I've noticed a big difference in the dodge and burn tools.  In CS4 I'd always set them at 10% so that I'd get subtle changes - gradually building up to how I wanted the

  • TS4253 iPhone 6 cannot import edited photos onto Macbook

    I have iOS 8 as well as the new Yosemite and latest iPhoto, as the Apple support recommends. However, I can still only import originals into iPhoto from my iPhone. It's maddening. What should I do?