I'm currently writing some robot code, and I've been wondering about using multiple threads in java. As far as I know, it's the same as using threads in any other java application, but some people on my team think differently. Here's what I think should work. I'm not sure that starting the thread in the constructor is the best idea, and I'm also not sure that I'm using thread.sleep() the right way. I know that I could start the thread from somewhere else by using new Thread(Vision).start();, but what would work with java for FRC?
Code:
public class Vision implements Runnable{
public Vision(){
new Thread(this).start();
}
public void run() {
while(processImages){
//image stuff here
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}