java opencv application thread problem
CanvasFrame
and OpenCVFrameGrabber
. I have a deveoped a Runnable
class called Detector
(full source here: http://bit.ly/l1Z3tY)
The Detector
class automatically runs a new Thread of itself by calling its start method:
public void start()
{
if (this.thread == null)
this.thread = new Thread(this);
this.isThreadActive = true;
this.thread.start();
}
The first time i call the start method from a Detector
instance everything works fine.
When i try to stop and restart the process it gives invalid thread state exception...
So i think the whole question here it's: "what's the best way to start/stop/restart a thread?"
TNX
Is the object you are stopping/restarting actually a Runnable, or is it a Thread? If I recall correctly, you can only run a thread once. If you want to run it more than once, you need to run the Runnable multiple times, not the Thread.
From the Thread documentation: It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.
精彩评论