Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default Can Timers only have one task?

    Hey there,

    I'm working on an animation class for one of my programs, and sometimes I need to adjust the frame delay.

    I'm working with Timers from java.util.Timer and I'm wondering if when I call the "schedule()" method, does it override the current task, or will it add a task.

    Ex: Will this code:
    Java Code:
    Timer t = new Timer();
    
    // First task, at 50 milisecs
    t.schedule(new TimerTask() {
    	@Override
    	public void run() {
    		// Code here
    	}
    }, 0, 50);
    
    // Second task, at 100 milisecs
    t.schedule(new TimerTask() {
    	@Override
    	public void run() {
    		// Code here
    	}
    }, 0, 100);
    So will the second task override the first one, or will both tasks be executed at the specified intervals?
    Good with: C/C++, DarkGDK, PHP, MySQL
    Current reading: The Linux Programming Interface

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    If your animation is in a Swing GUI, it's far better that you use javax.swing.Timer and not java.util.Timer.
    How to Use Swing Timers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)

    As for your posted question
    will the second task override the first one, or will both tasks be executed
    What happened when you tried it? All you need to test this are two tasks that print different Strings to the console via System.out. Surely a faster way of getting to know than waiting for someone on a forum to respond.

    db

Similar Threads

  1. I need help with timers
    By Chris Rice in forum New To Java
    Replies: 15
    Last Post: 09-04-2013, 07:02 PM
  2. Swing timers question?
    By intel i7 in forum AWT / Swing
    Replies: 5
    Last Post: 12-25-2010, 12:39 AM
  3. Job scheduling using timers in java
    By umapathy_sekar in forum New To Java
    Replies: 1
    Last Post: 09-13-2010, 05:18 PM
  4. Swing Timers Issue.
    By killpoppop in forum AWT / Swing
    Replies: 4
    Last Post: 03-09-2009, 11:17 PM
  5. Question on swing timers
    By Samgetsmoney in forum New To Java
    Replies: 5
    Last Post: 02-20-2009, 07:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •