Results 1 to 4 of 4
- 03-06-2012, 08:09 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Measure limited time for a process
Hi
I want to run a process in a thread during a limited time (say, 1000 nanoseconds). I created some method to measure the time. After the time is gone, a boolean variable turns into "false", and the thread should stop. Now, it does not seem to work, and I am not sure where to search for the error.
My question: should the following code turn the value of "busy" into "false" after 1000 nanoseconds, or not?
Thanks already for your answer!Java Code:long limitedTime = 1000; boolean busy; public void processing() { long startTime = System.nanoTime(); long duration = System.nanoTime() - startTime; if (duration < limitedTime) { busy = true; } if (duration => limitedTime( { busy = false; } }Last edited by Vinn; 03-06-2012 at 08:17 PM.
- 03-06-2012, 08:14 PM #2
Re: Measure limited time for a process
You never update the duration. So your first while loop will never exit. Add some print statements, or better yet step through it with a debugger, to understand exactly what's going on.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 03-06-2012, 08:24 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Re: Measure limited time for a process
Thanks Kevin
I changed the "while" into "if", but... that doesn't seem to make much sense either. Maybe indeed time to explore the debugger...
- 03-06-2012, 08:27 PM #4
Re: Measure limited time for a process
Your only problem is that you only set the duration once. It seems to me that you should be recalculating that each time.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
Advise.. What to do when you have too much limited time for a project
By Nazneen Ali in forum New To JavaReplies: 1Last Post: 08-06-2011, 02:17 AM -
Need help in quitting a unix process from java after a certain time
By umapathy_sekar in forum Advanced JavaReplies: 1Last Post: 11-09-2010, 12:42 PM -
Need help with Process execution time display
By murali18 in forum New To JavaReplies: 5Last Post: 03-18-2010, 11:19 PM -
How can I measure the data rate of my connection
By islamfunny in forum CLDC and MIDPReplies: 0Last Post: 09-25-2008, 03:27 PM -
How can I set a time out on the loading process
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 04:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks