View Full Version : Multithreading with Java? Anyone using it?
Specifically, I would like to put the camera and target detection on a separate thread, but would be interested in examples of doing anything in a separate thread.
SavtaKenneth
07-02-2010, 16:25
We are doing a multithreaded application. I'm at home right now so I don't have any hand on code examples but for how to program using threads in java look into Thread class and the Runnable interface. Basically a threaded camera/targer would look something like this
public class Targeter implements Runnable{
Arguments
Arguments
Arguments
Arguments
public void run(){
while(true){
aimTheTarger();
}
public void start(){
Thread p = new Thread(this,"This is a Thread");
p.start();
}
public class Vision implements Runnable{
Arguments
Arguments
Arguments
Arguments
public void run(){
while(true){
TakeAPicture();
}
public void start(){
Thread p = new Thread(this,"This is a Thread");
p.start();
}
Also look into the synchronized keyword which is useful for making sure threads don't interrupt each other.
Good luck
~Kenneth
Team #2212 The Spikes
spartango
07-02-2010, 23:39
If you have a look at the GRTFramework(code.google.com/p/grtframework), you'll notice that we use multithreading extensively, with sensor and actuator abstractions/drivers being independent threads, and controllers for specific robot mechanisms acting completely independently from each other. We have not noticed any real performance costs thus far, and thus strongly recommend a threaded model to segregated robot parts.
I'm not saying that threading has no performance costs, but for the purposes of this competition they are not noticeable even with java threads.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.