View Single Post
  #1   Spotlight this post!  
Unread 12-12-2012, 15:19
apples000's Avatar
apples000 apples000 is offline
Registered User
no team
 
Join Date: Mar 2012
Rookie Year: 2012
Location: United States
Posts: 222
apples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant future
Quick Question about Threads

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();
            }
        }
    }
}
Reply With Quote