Results 1 to 2 of 2

Thread: Tr

  1. #1
    machro is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Question Tr

    [edit]Excuse me for the weird title i gave this topic. I forgot it.[/edit]

    Hello,

    I have a question about a Thread. I want to create an application with a tread, and want to do every second a method. But if this method takes a long time, it takes longer than a second. Is there a methode so the Thread use just 1 second, whatever the time the method takes.

    Is this possible with SwingUtilities.invokeLater, or is this the wrong way of thinking?

    I hope you understand my question, my Englisch is not very well.


    Java Code:
    Thread t = new Thread(this);
    
    public void run(){
    	try{
    		doSomething();
    		t.sleep(1000);
    	}catch(InterruptedException ie){
    	}
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default

    Determine how long the method took, then only sleep for the remainder?

    For example, if the method takes 750 ms, you only want to sleep for 250 ms.

    What you should do when the method takes longer than a second is up to you. Do you want to interrupt the method, or simply not sleep afterwards?

    Using SwingUtilities.invokeLater simply causes an action to be carried out on the EDT. How do you think that will help you? Read the API and the tutorials to which it links.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Posting Permissions

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