View Single Post
  #1   Spotlight this post!  
Unread 09-02-2016, 16:15
seg9585's Avatar
seg9585 seg9585 is offline
Registered User
AKA: Eric
FRC #4276 (Surf City Vikings)
Team Role: Engineer
 
Join Date: Feb 2006
Rookie Year: 2001
Location: Boeing (Seal Beach, CA)
Posts: 520
seg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond repute
Java Threading Question

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?
__________________
My FIRST legacy:

Team 204 Student 2001, 2002 (Voorhees, NJ)
Team 1493 College Mentor 2006 - 2008 (Troy, NY)
Team 2150 Intern/Professional Mentor 2007, 2009 (Palos Verdes)
Team 4123 Lead Engineering Mentor 2012 (Bellflower, CA)
Team 4276 Engineering Mentor 2012-2016 (Huntington Beach, CA)