View Single Post
  #1   Spotlight this post!  
Unread 01-26-2011, 09:01 PM
flameout flameout is offline
AKA Ryan Van Why
FRC #0957 (SWARM)
Team Role: Alumni
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Oregon
Posts: 168
flameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to all
Netbeans doesn't like Thread.yield()

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.
Code:
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.getParticleAnalysisReport(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?
Reply With Quote