seg9585
09-02-2016, 16:15
Question to those of you who use Threading (class MyClass extends Thread implements Runnable) for various scripting:
We wrote a Thread class that carries out a script upon button press (in our case, performing about 5 mechanical timed functions in sequence to shoot our boulder). The script itself is in our void run(){} method and gets invoked upon callout of our shooterclass.start();
The script in run() is not an infinite loop -- it would merely end and I would *think* the thread itself would terminate.
So, when the script is complete and sometime in the future I press the same button, calling out MyClass.start(); a second time throws an exception. The only way I've gotten around this was to generate a new Thread (shooterclass = new MyClass(); ) before calling out shooterclass.start(); again.
Even though this works, I'm worried I'm just creating a ton of new threads that will bog down the roboRio eventually. What is the correct way to terminate a Thread? the API says Thread.stop() is deprecated
Should I just assume the thread is always running, allowing me to specifically call out shooterclass.run() in the 2nd iteration and beyond?
We wrote a Thread class that carries out a script upon button press (in our case, performing about 5 mechanical timed functions in sequence to shoot our boulder). The script itself is in our void run(){} method and gets invoked upon callout of our shooterclass.start();
The script in run() is not an infinite loop -- it would merely end and I would *think* the thread itself would terminate.
So, when the script is complete and sometime in the future I press the same button, calling out MyClass.start(); a second time throws an exception. The only way I've gotten around this was to generate a new Thread (shooterclass = new MyClass(); ) before calling out shooterclass.start(); again.
Even though this works, I'm worried I'm just creating a ton of new threads that will bog down the roboRio eventually. What is the correct way to terminate a Thread? the API says Thread.stop() is deprecated
Should I just assume the thread is always running, allowing me to specifically call out shooterclass.run() in the 2nd iteration and beyond?