Java - loop for X seconds

Associate
Joined
8 Apr 2004
Posts
2,053
SQL - how to lock table and allow only copying

Hi, I have a simple question here I hope you guys can help me with. Ignore the stuff below. Thought it would be better to just ask this new question here instead of making another thread.

At the moment, I have a database of stuff from which I made temporary table copies of. Then with my program, I work with these temporary tables, insert and updating values before I wipe them clean, so that the default values may be used again. This is to prevent any modifications to the original tables.

How would I go about locking the original tables, so that no changes can be made to it (unless I unlock it again), and only allow it to be read so that changes can be made with the temporary copies instead? I've already based most of my program around the use of these temporary copies so I would prefer to not change this idea if possible, even if there is a more efficient way.

I've already made quite a few mistakes where I failed to notice I typed stmt.executeQuery ("UPDATE class...") instead of stmt.executeQuery("UPDATE tempclass...") and as a result, had to go back and update all my table values back to their defaults again!


It's simple: how do I get something to continuously loop for a certain amount of time?

I currently have a timetabling algorithm which schedules classes into a weekly timetable, analyses it and then produces a score. So far, if the user specifies they would like to loop this 50 times, then at the end of the 50th iteration, the best score so far is recorded.

What I would like to achieve is to allow the user to specify a certain number of minutes, say 10. Then the algorithm loops until the 10 minutes have expired, at which the algorithm stops and records the best score so far. I was thinking something like:

bestscore = 0;
do
{

scheduleclasses();
producescore();
if(score>bestscore)
{
bestscore = score;
}
}
while(thereistimeleft)


Print("Best score produced was: " + bestscore);

The parts in bold are what I'm interested in. If anyone has an answer, or even a link to a webpage that explains it, it will be much appreciated. Many thanks
 
Last edited:
Back
Top Bottom