![]() |
interrupting current execution
hey all, for my programming course i was to write a progam that uses a combinatorial search to find a solution, the problem is of course, that as the amount of data increases so is the time to find a solution. What i want to do is to interrupt such a time taking search and go onto the next possible candidate that might produce a correct answer. Without using threads is it possible to employ a timer of some sort so when the processing takes too long it could interrupt and tell it to move on to the next candidate? This is the Knight Tour problem, i guess many of you have dealt with it one point in your lifetime. Any advice greately appreciated.
|
I would recommend looking into some more efficient ways in organizing your data. Maybe sorting your data would make the search A LOT more manageable.
Instead of having your data as just some random places just organize and use binary search. |
yes i know it could be done more efficiently if more advanced data structures than simple array have been used, thats not the point here, Im looking for the way to interrupt something that takes to long to arrive at the correct answer.
|
Why not just check the time at each iteration or recursion of the loop? It seems to me as if you wouldn't need threads.
|
you just made me think of something that could actually work, ill try something similar...ill let you all know if it worked, thanks
|
I found a place in my code where i could call elapsed() which made following code usable. Sometimes when i overthink a problem i do not see really simple solutions, I tend to think of too complicated stuff....are u like that? hehe, i mean look at this:
:
import java.util.Date;Arevos! thanks for opening my eyes lol |
Your code creates a new Date object every time elapsed is called. You should use System.currentTimeMillis() instead.
You should also take into account the fact that performing such a check on each iteration of a loop will cost time and processing power, albeit a miniscule amount. |
yes, i've relized it, thanks for pointing me to the right function
|
| All times are GMT -5. The time now is 1:43 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC