#I can't change the name of the timertask thread from another thread

21 messages · Page 1 of 1 (latest)

obsidian gazelle
#
        
        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
steep ruinBOT
#

This post has been reserved for your question.

Hey @obsidian gazelle! Please use /close or the Close Post button 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.

hasty kite
#

Dude, trying to fix what? Seriously now

obsidian gazelle
#

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

hasty kite
#

notify() has nothing to do with names

obsidian gazelle
#

you need to enter the thread name.notify() to specify the thread to notify()

hasty kite
#

This is an object. They're not names

obsidian gazelle
#

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

hasty kite
#

You could just make one, but it seems weird to have a TimerTask wait

obsidian gazelle
#

Where would I make one?

#

inside it

hasty kite
obsidian gazelle
#

because the main runs before the timertask thread runs

hasty kite
#

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

obsidian gazelle
#

How do I create it beforehand?

hasty kite
#

Like Object monitor = new Object();

obsidian gazelle
#

Oh, but then how would I turn that into a thread Object

hasty kite
#

What are you speaking about? You don't want a thread, you want a monitor to wait()/notify() on

obsidian gazelle
#

oh, my research failed me, sorry

#

should I close the post?