I have started a Java coding short course at a university about 5 months ago. I have learnt quite the amount of things with regards to Java coding, but am still lacking in other things such as threads, handling exceptions, or even making JFrame games. I decided to embark on a text based game to just learn and figure out how a game loop should work (kind of), and how the logic should work (still, very "kind of"). The game I wrote runs with if-else commands, thus you get displayed a screen, type in the command of the option you want to pick, and it bumps you to the next menu, very standard of course. I run these if-else statements within nested for loops.
My nested for loops looks like the following:
// This is just an example, they're actually a lot more cluttered
// in my actual source code.
mainMenu.writeOutput();
reply = keyboardInput.nextLine();
for (int i = 0; i <= 10; i--)
{
for (int ii = 0; i <= 10; i--)
{
if (reply.equalsIgnoreCase("/help")
{
System.out.println("Here I have a separate call to a class
file (excuse me, forgot the exact wording), thus it
call something like help.writeOutput(); to display
the help menu");
reply = keyboardInput.nextLine();
if (reply.equalsIgnoreCase("/makegameeasy")
{
// Just an example.
gamedifficultyEasy.writeOutput();
reply = keyboardInput.nextLine();
if (reply.equalsIgnoreCase("/back")
{
mainMenu.writeOutput();
reply = keyboardInput.nextLine();
break;
}
}
else if (reply.equalsIgnoreCase("/makegamedifficult")
{
// Another example.
gamedifficultHard.writeOutput();
reply = keyboardInput.nextLine();
if (reply.equalsIgnoreCase("/back")
{
mainMenu.writeOutput();
reply = keyboardInput.nextLine();
break;
}
}
else if (reply.equalsIgnoreCase("/back")
{
mainMenu.writeOutput();
reply = keyboardInput.nextLine();
break;
}
}
else
{
System.out.println("Here I print out an error for incorrect
input received, standard fare.");
mainMenu.writeOutput();
reply = keyboard.nextLine();
break;
}
}
}
As mentioned, the above is just an example, it's not very elegant, and I can probably use Exceptions for any incorrect info submitted by the user, however I do not know too much of Exceptions to comfortably add them, so I'll do that at a later time, however my main issue at the moment is a part of my game where "resource mining" has to be done on regular intervals. I have been all over Google, but still can't quite catch how to set a Thread or Timer up for my game so it does the mining automatically, and the player can go on with their game.
The game is essentially one of those games where you build up a base, upgrade your mining tools, and generate more "stuff". I have pasted a few blocks of code from my "mining" class file below that will basically run how much of one thing should be mined. In the game you will be able to buy upgrades of course, so it will get factored into your mining speed.
// I initiate my variables a lot earlier, but just for some
// clarity, I have initiated the variables in the below methods,
// they will not work correctly anyway, I am aware of that, however
// I didn't want to add the other "get, set and initiate"
// variables and methods everywhere, as to not spam this block of code.
// upgradeOS, upgradeHF, and upgradeLM all have their own respective
// set and get methods. They are also all int variables.
public void handleOS()
{
// OS = short for Oxygen Silo
int mineOS = os.getStoredO2() + (1 * upgradeOS);
os.setStoredO2(mineOS);
}
public void handleHF()
{
// HF = short for Hydrogen Fuel
int mineHF = hf.getStoredO2() + (1 * upgradeHF);
hf.setStoredO2(mineHF);
}
public void handleLM()
{
// LM = short for Liquid Minerals
int mineLM = lm.getStoredMinerals() + (1 * upgradeLM);
lm.setStoredMinerals(mineLM);
}
// This is what's going to run the whole time on the set intervals.
public void mine()
{
mineOS = os.getStoredO2() + (1 * upgradeOS);
mineHF = hf.getStoredO2() + (1 * upgradeHF);
mineLM = lm.getStoredMinerals() + (1 * upgradeLM);
os.setStoredO2(mineOS);
hf.setStoredO2(mineHF);
lm.setStoredMinerals(mineLM);
}
// Using 10 seconds here to have it update as quickly as possible so I can
// see any changes. This is just here to write an output.
public void getUpgradeInfo()
{
System.out.println("Oxygen: " + (1 * upgradeOS) + " / per 10 seconds.");
System.out.println("Hydrogen: " + (1 * upgradeHF) + " / per 10 seconds.");
System.out.println("Liquid Mineral: " + (1 * upgradeLM) + " / per 10 seconds.");
}
I'm not the best naming schemes for my materials...
TL;DR: I can't figure out how to implement a thread or timer just for the above mentioned mine() method since I do not have the appropriate amount of knowledge. My if-else rules aren't too elegant, but I'll work on those of course. Basically the if-else rules should run separately from the mine() method, and you can do some AFKing without the game updating the System.out output, thus you can be floating in, for example, the Oxygen Silo upgrade menu, and you won't be bounced back to a different menu due to a thread "waking up", such as being bounced to the main menu, but the mine() method will still generate resources in the background as it should.
Any help on this, or just even a nudge in the right direction will be greatly appreciated.
To answer the question you asked, you can do something like this:
import java.util.*;
TimerTask tt = new TimerTask() {
public void run() {
mine();
}
}
Timer t = new Timer();
t.scheduleAtFixedRate(tt, 0, 1000);
Alternatively, you can use an ActionListener and the swing timer in a similar way. This has the advantage of being Thread-safe in case you build a swing gui on top
Lastly, you should check out the usage of synchronized and volatile to make sure that the variable(s) that are updated in mine() are done so in a thread-safe way
Thanks to #ControlAltDel, definite shove in the right direction. I have taken a bit of code and set it up like this:
import java.util.*;
// extends TimerTask needed
public class TimerTestOne extends TimerTask
{
// Needed
#Override
public void run()
{
TimerTestTwo ttt = new TimerTestTwo();
mine();
}
// Needed, method doesn't need the same name though.
private void completeTask()
{
try
{
//assuming it takes 10 secs to complete the task
Thread.sleep(10000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
// You will need to define the following line of code:
TimerTask tt = new TimerTestOne();
Scanner keyboard = new Scanner(System.in);
String reply;
// Following 2 lines of code, yup, need them.
Timer timer = new Timer(true);
timer.scheduleAtFixedRate(tt, 0, 10*1000);
previousMenu();
for (int i = 0; i <= 10000; i++)
{
for (int ii = 0; ii <= 10000; i++)
{
System.out.println("Go to another menu?");
reply = keyboard.nextLine();
if (reply.equalsIgnoreCase("/yes"))
{
yes();
reply = keyboard.nextLine();
}
}
}
}
// I added the following methods, just so I didn't have to work
// off 2 class files.
public void mine()
{
System.out.println("Mined");
}
public static void yes()
{
System.out.println("Next menu");
}
public static void previousMenu()
{
System.out.println("Previous menu");
}
}
So there, if anyone ever needs to have a look at setting a timer up that won't break your text based game.
Related
I am making a timed quiz where there should be a timer on each question.
I want my code to output a question for 20 seconds and ask for an input for the answer and when the time is up, question number 2 should show up. I am stuck on what should I do to have that, a reference is enough, I just don't know what to read on about, I am using java.util.Timer and TimerTask.
I also tried
ExecutorService but i only see examples that it shutsdown after the timer, i need to post another question after the timer ends, not shotdown the program since i need a time limit for each question and not a timer for the whole quiz.
I tried this
if(seconds<=20)
{
question1();
}
else if (seconds<=40||seconds>=21)
{
new ProcessBuilder("cmd","/c","cls").inheritIO().start().waitFor();
question2();
}
I also tried using while
while(seconds<=20){
question1();
}
while(seconds<=40||seconds>=21){
new ProcessBuilder("cmd","/c","cls").inheritIO().start().waitFor();
question2();
}
This is what my question method looks like.
public static void question2(String... args) throws
IOException, InterruptedException
{
System.out.println("");
System.out.printf("%72s\n","QUIZ FOR PHILIPPINE HISTORY");
System.out.println("");
System.out.printf("%64s\n","Question #2");
System.out.println("");
System.out.println("\t\t\t\t\t WHO DISCOVERED PHILIPPINES?");
System.out.println("\n\t\t\t\t\t\tA. Fernando Magellan");
System.out.println("\t\t\t\t\t\tB. Ferdinand Megallan");
System.out.println("\t\t\t\t\t\tC. Ferdinand Magellan");
System.out.println("\t\t\t\t\t\tD. Fernando Poe");
System.out.println("\n\t\t\t\t\t\tTYPE YOU ANSWER HERE: ");
char answer2 = a.nextLine().charAt(0);
switch (sagot2)
{
case 'B':
case 'b':
score++;
seconds = 21;
System.out.print("You are CORRECT!");
break;
default:
System.out.print("You are WRONG");
seconds = 21;
break;
}
}
This is the beginning of my code plus the timer and timertask.
import java.util.Timer;
import java.util.TimerTask;
import java.util.Scanner;
import java.io.IOException;
public class q2 {
static int seconds = 0;
static Scanner a=new Scanner(System.in);
static Timer timer = new Timer();
static int number = 1;
static int score = 0;
public static void mema(){
TimerTask task = new TimerTask ()
{
public void run()
{
seconds++;
System.out.print(seconds);
}
};
timer.schedule(task,1000,1000);
}
I also tried using this but it doesnt do the other method after 5 seconds.
long start = System.currentTimeMillis();
long wait = 5000;
long end = start + wait;
long end1 = end + wait;
while (System.currentTimeMillis() < end)
{
question1();
}
while (System.currentTimeMillis() < end1 || System.currentTimeMillis() > end)
{
question2();
}
Various things that you did make your code more complicated then it ought to.
First of all, avoid fixing details such as "this is the first question" versus "this is the second question".
Instead: focus on basic elements that you need. In your case: you want to display a question for a certain amount of time. Afterwards, the program should either display another question - or probably give a summary and end.
Thus: write a class/method that simply puts up a question and then waits. And then think how you could re-use that code to put up any number of questions in sequence.
For the "timing": given the fact that you are a beginner, I would recommend you to not go "fully multi-threaded" (meaning: tasks, and schedulers) at this point. Instead, "waiting for some time" can easily be achieved via
getting the currentTime
endTime = currentTime + 20 sec
looping until that endTime is reached
Thing is: you learn programming by exploring your options and trying many things. Thus I gave you hints - not code.
everyone!
I have just created a brute force bot which uses WebDriver and multithreading to brute force a 4-digit code. 4-digit means a range of 0000 - 9999 possible String values. In my case, after clicking the "submit" button, not less than 7 seconds passes before the client gets a response from the server. So, I have decided to use Thread.sleep(7200) to let the page with a response be fully loaded. Then, I found out that I couldn't afford to wait for 9999*7,5 seconds for the task to be accomplished, so I had to use multithreading. I have a Quad-Core AMD machine with 1 virtual core per 1 hardware one, which gives me the opportunity to run 8 threads simultaneously. Ok, I have separated the whole job of 9999 combinations between 8 threads equally, each had got a scope of work of 1249 combinations + remainder thread starting at the very end. Ok, now I'm getting my job done in 1,5 hours (because the right code appears to be in the middle of the scope of work). That is much better, BUT it could be even more better! You know, the Thread.sleep(7500) is a pure waste of time. My machine could be switching to other threads which are wait() because of limited amount of hardware cores. How to do this? Any ideas?
Below are two classes to represent my architecture approach:
public class BruteforceBot extends Thread {
// All the necessary implementation, blah-blah
public void run() {
brutforce();
}
private void brutforce() {
initDriver();
int counter = start;
while (counter <= finish) {
try {
webDriver.get(gatewayURL);
webDriver.findElement(By.name("code")).sendKeys(codes.get(counter));
webDriver.findElement(By.name("code")).submit();
Thread.sleep(7200);
String textFound = "";
try {
do {
textFound = Jsoup.parse(webDriver.getPageSource()).text();
//we need to be sure that the page is fully loaded
} while (textFound.contains("XXXXXXXXXXXXX"));
} catch (org.openqa.selenium.JavascriptException je) {
System.err.println("JavascriptException: TypeError: "
+ "document.documentElement is null");
continue;
}
// Test if the page returns XXXXXXXXXXXXX below
if (textFound.contains("XXXXXXXXXXXXXXXx") && !textFound.contains("YYYYYYY")) {
System.out.println("Not " + codes.get(counter));
counter++;
// Test if the page contains "YYYYYYY" string below
} else if (textFound.contains("YYYYYYY")) {
System.out.println("Correct Code is " + codes.get(counter));
botLogger.writeTheLogToFile("We have found it: " + textFound
+ " ... at the code of " + codes.get(counter));
break;
// Test if any other case of response below
} else {
System.out.println("WTF?");
botLogger.writeTheLogToFile("Strange response for code "
+ codes.get(counter));
continue;
}
} catch (InterruptedException intrrEx) {
System.err.println("Interrupted exception: ");
intrrEx.printStackTrace();
}
}
destroyDriver();
} // end of bruteforce() method
And
public class ThreadMaster {
// All the necessary implementation, blah-blah
public ThreadMaster(int amountOfThreadsArgument,
ArrayList<String> customCodes) {
this();
this.codes = customCodes;
this.amountOfThreads = amountOfThreadsArgument;
this.lastCodeIndex = codes.size() - 1;
this.remainderThread = codes.size() % amountOfThreads;
this.scopeOfWorkForASingleThread
= codes.size()/amountOfThreads;
}
public static void runThreads() {
do {
bots = new BruteforceBot[amountOfThreads];
System.out.println("Bots array is populated");
} while (bots.length != amountOfThreads);
for (int j = 0; j <= amountOfThreads - 1;) {
int finish = start + scopeOfWorkForASingleThread;
try {
bots[j] = new BruteforceBot(start, finish, codes);
} catch (Exception e) {
System.err.println("Putting a bot into a theads array failed");
continue;
}
bots[j].start();
start = finish;
j++;
}
try {
for (int j = 0; j <= amountOfThreads - 1; j++) {
bots[j].join();
}
} catch (InterruptedException ie) {
System.err.println("InterruptedException has occured "
+ "while a Bot was joining a thread ...");
ie.printStackTrace();
}
// if there are any codes that are still remain to be tested -
// this last bot/thread will take care of them
if (remainderThread != 0) {
try {
int remainderStart = lastCodeIndex - remainderThread;
int remainderFinish = lastCodeIndex;
BruteforceBot remainderBot
= new BruteforceBot(remainderStart, remainderFinish, codes);
remainderBot.start();
remainderBot.join();
} catch (InterruptedException ie) {
System.err.println("The remainder Bot has failed to "
+ "create or start or join a thread ...");
}
}
}
I need your advise on how to improve the architecture of this app to make it successfully run with say, 20 threads instead of 8. My problem is - when I simply remove Thread.sleep(7200) and at the same time order to run 20 Thread instances instead of 8, the thread constantly fails to get a response from the server because it doesn't wait for 7 seconds for it to come. Therefore, the performance becomes not just less, it == 0; Which approach would you choose in this case?
P.S.: I order the amount of threads from the main() method:
public static void main(String[] args)
throws InterruptedException, org.openqa.selenium.SessionNotCreatedException {
System.setProperty("webdriver.gecko.driver", "lib/geckodriver.exe");
ThreadMaster tm = new ThreadMaster(8, new CodesGenerator().getListOfCodesFourDigits());
tm.runThreads();
Okay, so everyone can't wait until my question will get a response so I decided to answer it as soon as I can (now!).
If you would like to increase a performance of a Selenium WebDriver-based brute force bot like this one, you need to reject using the Selenium WebDriver. Because the WebDriver is a separate process in the OS, it does not even need a JVM to run. So, every single instance of the Bot was not only a thread managed by my JVM, but a Windows process also! This was the reason why I could hardly use my PC when this app was running with more than 8 threads (each thread was invoking a Windows process geckodriver.exe or chromedriver.exe). Okay, so what you really need to do to increase performance of such a brute force bot is to use HtmlUnit instead of Selenium! HtmlUnit is a pure Java framework, its jar could be found at Maven Central, its dependency could be added to your pom.xml. This way, brute forcing a 4-digit code takes 15 - 20 minutes, taking into account that after each attempt the website responds not faster than 7 seconds after each attempt. To compare, with Selenium WebDriver it took 90 minutes to accomplish the task.
And thanks again to #MartinJames, who has pointed that Thread.sleep() does let the hardware core to switch to other threads!
Hello again stack community,
I am working on a program to graphically display prompts, stored in a 2D array, and their correct response counterparts - I start off by calling the creation of a Menu object:
public static void main (String [] args){
SwingUtilities.invokeLater(new Runnable(){
public void run() { new Menu(); }
});
}
Within Menu I define various buttons:
JButton chem3Button, chin1Button, mathstatButton//etc...
followed by an action listener that follow the addition of properties such as the the tooltip and such:
mathstatButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent j) {
new matstatMenu();
}
});
which in turn passes control to matstatMenu, which allows the selection of an area in Mathematics, which in this case is only one, the available:
mathstatb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent l) {
new SwingImplementation(2, 1);
}});
Which sends Subject 2 (Math), and Subject Subset 1 (Descriptive Statistics) to SwingImplementation via the mathstatb1 button, to fly through this loop that copies the statistics array to oneRay:
case 2:
switch(unit){
case 1:
oneRay = new String[Master.MathaRay_Part2.length][2];
for(int i = 0; (Master.MathaRay_Part2.length) > i; i++){
oneRay[i][0] = Master.MathaRay_Part2[i][0]; oneRay[i][1] =
Master.MathaRay_Part2[i][1];} break;
default: System.exit(0); break;
} break;
and then fails to progress through this do-loop, which cycles infinitely despite the fact that the array Master.MathaRay_Part2 is full and by the above code should be fully copied.
Why is this do loop failing, or rather, never exiting?
do{
System.out.println("C");
pick = random.nextInt(oneRay.length);
}while((oneRay[pick][0]).isEmpty());
Please, I am just a swing-neophyte trying to create a program to help myself and peers in school, any help will be greatly appreciated.
I'm not sure what your problem is - there isn't enough code here for me to figure it out; and I know nothing about the Master.MathaRay_Part2 class. However, doing the following should help you, and would help me help you if you edit the results into your original post.
First, add the following function to your class that has the do loop:
private static final String toTwoDArrayString(Object[][] arr) {
StringBuilder sb = new StringBuilder();
sb.append('[');
boolean first = true;
for(Object[] row : arr) {
if (!first) {
// Requires Java 7. replace %n with either \n or \r\n for Java 6
sb.append(String.format(",%n "));
}
first = false;
sb.append(Arrays.toString(row));
}
sb.append(']');
return sb.toString();
}
Second, make sure that Master.MathaRay_Part2.toString() is implemented in a useful way, if it isn't already. In Eclipse, you can use Right Click -> Source -> Generate toString()...
Finally, immediately before the do loop, call:
System.out.println(toTwoDArrayString(onepick));
I need to check how many events are detected within 2 seconds. I have the timer working and I have everything else working...but I ran into a problem: the loop only checks one time, per second and I can't seem to figure out how to fix that. I need it to check constantly during these two seconds to see how many events there were in total!
Here is what I have:
int seconds = 0;
System.out.println("Seconds: " + seconds);
while(seconds < 2)
{
//Wait 1 second
try {
Thread.sleep(1000);
}
catch(Exception e) {}
seconds++;
System.out.println("Seconds: " + seconds);
//This needs to be looping the whole time.
//But right now, it's being blocked and only checked once
if(eventDetected() && seconds <= 2){
events++;
}
}
So you can see my problem. I can't split them up because then the second timer would run, and THEN eventDetected() would be checked. I need it to check constantly DURING the two second timer...so I basically need both things to happen at once. Is there any way I can do this?
Thanks for any help ahead of time!
I think your design pattern needs work -- I don't know what type event you're looking to detect, but no matter how short your sleep time is, there's a chance you could miss an event using the current pattern. Here's what I suggest:
Have eventDetected() increment your events counter. That way, you won't miss an event.
Then, you just need a way to turn on and off listening (and perhaps resetting the event counter). If you're sure that in you're current pattern you are really in a different thread that won't block your eventDetected() method, you could set a flag to check. For example:
When you want to start listening:
listenForEvents = true;
In eventDetected():
if (listenForEvents) { events++; }
When you want to stop listening (for example, after your Thread.sleep() call):
listenForEvents = false;
With multithreading, make sure to watch out for concurrency issues checking and setting the variables, of course.
I would tell you what kind of event I have to keep track of but then I'd have to kill you :D
Answered my own question. Hopefully this will help anyone else out who has a similar problem at some point! I looked up multithreading a bit...
I created a new class EventTimer which implements Runnable, with a public field for seconds:
public class EventTimer implements Runnable{
int seconds;
static int timerThreadCount = 0;
Thread t;
public EventTimer() {
timerThreadCount++;
this.seconds = 0;
t = new Thread(this, "Event Timer");
t.start(); // Start the thread
}
#Override
public void run() {
// TODO Auto-generated method stub
while(seconds < 2)
{
//Wait 1 second
try {
Thread.sleep(1000);
}
catch(Exception e) {
System.out.println("Waiting interupted.");
}
seconds++;
System.out.println("Seconds: " + seconds);
}
}
}
Then I used an instance of the EventTimer, and used a while loop & if statement to solve my problem.
EventTimer t = new EventTimer();
while(t.seconds < 2){
if(eventDetected()) events++;
}
It was actually quite simple! I realize that each iteration of my loop of operation (since the entire code piece above is inside an infinite loop) will create a new EventTimer thread and I will eventually run into memory problems however. How would I close/end a thread after the timer has reached 2 seconds?
I try to handle the output of different runnables wihtin another thread. First I add all runnables to a set and try to trigger their progress, which is saved into a map toether with the category. The category is the identifier for each runnable. There can exist only one runnable per category.
After that I try to write out the output in a progress bar on the stdout. But it is empty (0%) everytime. The strange thing is, when I am debugging in Eclipse, step by step, the progress bar seems to work correctly. I cannot find the problem, maybe it's some timing problem, or something else.
Can some tell what I am doing wrong?
If someone knows a better way of handling the output of different Threads, please let me know. I am would be happy, definitely.
Thanks in advance for your help.
This is my WriterThread:
public class WriterT extends Thread {
Set<Runnable> my_runnables = new HashSet<Runnable>();
Map<String, Integer> all_runnable_progress = new HashMap<String, Integer>();
public WriterT() {
}
public void add(Runnable r) {
my_runnables.add(r);
}
public void run() {
if(!my_runnables.isEmpty()) {
int progress = 0;
while(true) {
for(Runnable r : my_runnables) {
if(r instanceof Verify_TestRun) {
Verify_TestRun run = (Verify_TestRun)r;
progress = run.get_progress();
all_runnable_progress.put(run.get_category(), progress);
}
}
if(progress <= 100) {
print_progress();
} else {
break;
}
try {
Thread.sleep(150);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
private void print_progress() {
StringBuilder str_builder = new StringBuilder();
for(String cat : all_runnable_progress.keySet()) {
int percent = all_runnable_progress.get(cat);
str_builder.append(cat + "\t[");
for(int i = 0; i < 25; i++){
if( i < (percent/4)){
str_builder.append("=");
}else{
str_builder.append(" ");
}
}
str_builder.append("] " + percent + "%" + "\t");
}
System.out.print("\r" + str_builder.toString());
}
}
Updated answer after new information
So if I understand you correctly, you want to go over each test run you are tracking, see if any of them is still running i.e. the progress is less than 100 and print the progress as long as they're not all finished.
First, you need to consider what Stephen C said in his answer - you (probably) want to sum up the progress values of each of the test runs. Then, check if the sum comes out to less than 100 for each test run. If it does, at least 1 test run is still in progress and you print progress and stay in your loop. If you find that your sum comes out to exactly 100 for each test run, then you're all done. You print progress one final time to update the output to reflect 100% for each and then break from the loop.
Here is my suggested implementation that makes minor changes to your code:
public void run() {
if(!my_runnables.isEmpty()) {
int progress = 0;
while(true) {
for(Runnable r : my_runnables) {
if(r instanceof Verify_TestRun) {
Verify_TestRun run = (Verify_TestRun)r;
//change #1 - sum up the progress value of each test
progress += run.get_progress();
all_runnable_progress.put(run.get_category(), progress);
}
}
//change #2 - break when all done
if(progress < (100 * my_runnables.size()) ) {
//check if tests are still running i.e. there are test runs with progress < 100
print_progress();
} else {
//otherwise print one last status (to update all status' to 100%) before stopping the loop
print_progress();
break;
}
try {
Thread.sleep(150);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Shouldn't progress be checked within the for loop? What you're doing right now is iterating over all your Runnables and setting progress to the progress value and adding it to the map. But then you immediately move on to the next Runnable. The net result is that the value of progress once you leave the loop is the value of the last Runnable you handled.
I think that this might be the problem line:
progress = run.get_progress();
Given the context, progress will end up as the last value returned by a Verify_RunTest, but I suspect you mean it to be the sum of the values.
(BTW - Verify_RunTest is bad style. It should be VerifyRunTest.)