Apparently threads don’t like boolean methods ><. My headache is gone alas!
What do you mean “doesn’t work”? How do you tell if a method works or not?
Simply looking at the code, I can see several… Perhaps not errors, but places where it seems as though there could be something “wrong” going on.
I’m going to assume that your code is either single threaded or correctly synchronized. If either of these conditions are untrue, then it’s likely that you’re dealing with what’s called a Heisenbug, which is to say: You’ve got a classic multi-thread error in there and the ‘System.out’ is causing it to run correctly because it provides an extra space for your multiple threads to interleave.
Line 9: You set eventAlive = true, then in line 7 you set it again.
Line 10 and 16: This should be an if else, instead of two ifs (The conditions are mutually exclusive).
Line 8: Unless something else, IE- TEtarget.GEStart(), updates currTime or TimeWizard.mainTimeSecs then the if statement will always hit either the if or the else for each repetition.
Line 6: Unless eventContinue is changed by TEtarget.GEStart() then line 37 is never reached.
Line 6: I’m assuming that TEtarget.GEStart() will update something, otherwise your loop will never expire.
A bit more information about what’s supposed to be happening with the code could be useful, 'cause otherwise all of my observations are shots in the dark, so to speak.
Meaning it doesn’t work is that the thread just doesn’t go/stop if I take the Sys outs away.
The object of this method is to start a loop which it looks at my games System time and takes a snapshot of the current time and then designated time to time something for example if its 30secs game time and you want 5seconds of something to start or sleep it goes till 35secs then terminates.
TEtarget.GEStart(); is the TimerEvent classes calling to a Interface method GEStart which is passed through the constructor during initialization of the object. GeStart can be anything its just like Runnable.
if (TimeWizard.mainTimeSecs <= currTime) once false it = else and eventContinue to false ending the while loop.
Btw this is added to a thread.
public void teGO() {
new Thread(this).start();
}
@Override
public void run() {
this.startEvent();
}
End result
new TimedEvent(9,this).teGO();
Pretty much this class is a custom timer running by my games system time. Any entity or object can use this to trigger events because I have a method which tells once this is finished or not via TimerEvents method which other classes check.
public boolean eventStatus() {
return eventAlive;
}
You are able to pick a time to Run during the duration say for 5 seconds or choose to go after 5 seconds eventForDuration =true then it goes for the designated duration otherwise false it goes after the set duration.
So yea it appears my thread is just hanging for some reason.
EDIT: Solved…yea changing from a boolean to a void fixed things and just cleaning the code a bit, thanks guys UprigthPath good calls btw.