flameout
26-01-2011, 21:01
When ever I try to use Thread.yield (in my vision thread), NetBeans complains with "invoking yield() on java.lang.Thread" (just a warning, not an error).
I'd prefer to have code with no warnings, and am concerned that I'm not doing this right.
Here's the faulty class. Another class creates the thread object and calls start() on it.
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.BinaryImage;
public class Vision implements Runnable {
AxisCamera axis;
ColorImage colimage;
MonoPosterize posterize;
BinaryImage binimage;
Thread thread;
// Updates the target positions if a new image exists.
public void refresh() {
try {
if (colimage != null) colimage.free();
colimage = axis.getImage();
if (binimage != null) binimage.free();
binimage = posterize.posterize(colimage);
System.out.println(binimage.getNumberParticles());
System.out.println(binimage.getParticleAnalysisRep ort(0));
} catch (Exception e) {
System.out.println(e);
}
}
private void WaitForImage() {
while (!axis.freshImage()) {
Thread.yield();
}
}
// This is run by Thread.start();
public void run() {
thread = Thread.currentThread();
thread.setPriority(Thread.MIN_PRIORITY);
}
}
Can someone verify that I'm coding this correctly?
I'd prefer to have code with no warnings, and am concerned that I'm not doing this right.
Here's the faulty class. Another class creates the thread object and calls start() on it.
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.BinaryImage;
public class Vision implements Runnable {
AxisCamera axis;
ColorImage colimage;
MonoPosterize posterize;
BinaryImage binimage;
Thread thread;
// Updates the target positions if a new image exists.
public void refresh() {
try {
if (colimage != null) colimage.free();
colimage = axis.getImage();
if (binimage != null) binimage.free();
binimage = posterize.posterize(colimage);
System.out.println(binimage.getNumberParticles());
System.out.println(binimage.getParticleAnalysisRep ort(0));
} catch (Exception e) {
System.out.println(e);
}
}
private void WaitForImage() {
while (!axis.freshImage()) {
Thread.yield();
}
}
// This is run by Thread.start();
public void run() {
thread = Thread.currentThread();
thread.setPriority(Thread.MIN_PRIORITY);
}
}
Can someone verify that I'm coding this correctly?