Results 1 to 2 of 2
Thread: Tr
- 12-30-2010, 01:33 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
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){ } }
- 12-30-2010, 01:52 PM #2
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!


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks