TimerTask physicsOn = new TimerTask() {
public void run() {
if (!(movers[0] == null)) {
Object[][] mover = (Object[][]) movers[0];
timeAtLastMove = System.nanoTime();
for (int i = 0; i < 600 && !(mover[1][i] == null); i += 3) {
mover[1][i] = (double) mover[1][i] + (double) mover[3][0];
mover[1][i+1] = (double) mover[1][i+1] + (double) mover[3][0];
mover[1][i+2] = (double) mover[1][i+2] + (double) mover[3][0];
System.out.println(mover[1][i]);
}
/*Test Collision Here*/
movers[0] = null;
System.out.println(mover[0][1]);
} else {physics.Wait();}
}
};
/*-------------------------------------------------------------------------------------------------*/
Timer physicsActive = new Timer();
Notify()```
This is the code I need to work, I spent a day trying to fix this
#I can't change the name of the timertask thread from another thread
21 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @obsidian gazelle! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Dude, trying to fix what? Seriously now
I can't notify() the thread because it is nameless
The main runs before the timer and has no name to use
So do I need to initialize the name outside the thread? but how
notify() has nothing to do with names
you need to enter the thread name.notify() to specify the thread to notify()
This is an object. They're not names
It still has nothing to reference it with, or to run notify() with
sorry if my java terminology is wrong, I've done a lot of other coding
You could just make one, but it seems weird to have a TimerTask wait
Well names are names and stuff that aren't names aren't names
because the main runs before the timertask thread runs
You'll probably need to share the monitor object, otherwise it won't exactly be useful. So you create it beforehand and you pass it to everything that needs to synchronize on it
How do I create it beforehand?
Like Object monitor = new Object();
Oh, but then how would I turn that into a thread Object
What are you speaking about? You don't want a thread, you want a monitor to wait()/notify() on