Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Multithreading with Java? Anyone using it? (http://www.chiefdelphi.com/forums/showthread.php?t=82113)

adamdb 07-02-2010 14:45

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

Re: Multithreading with Java? Anyone using it?
 
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

Code:

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

Re: Multithreading with Java? Anyone using it?
 
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.


All times are GMT -5. The time now is 09:39.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi