I'm writing a piece of video analysis software using Java and the Xuggler library. My code is all single threaded, but some of it is being called from a Xuggler thread.
I have to process a directory full of video files, so I iterate through the files and for each one I start an instance of IMediaReader then process the frames. When I'm finished I detach the listener and close the reader. Like this:
public void ProcessFrames(VideoFile file, MediaProcessor processor, int ImageType)
{
IMediaReader mediaReader = ToolFactory.makeReader(file.location);
mediaReader.setBufferedImageTypeToGenerate(ImageType);
mediaReader.addListener(processor);
mediaReader.open();
IError videoDecodeError = null;
while (videoDecodeError == null &&
processor.isListenerFinishedWithStream() == false)
{
try {
videoDecodeError = mediaReader.readPacket();
} catch(Exception ex) {
ex.printStackTrace();
}
}
System.out.println("Closing media reader.");
mediaReader.close();
mediaReader.removeListener(processor);
}
I've noticed that every time I create a new IMediaReader it seems to leave a thread open and just hanging around. The problem is that I can't seem to find any information about the orphaned threads. In Eclipse they show up as "Thread [Thread-2] (Running)".
I can't find any information about where the thread is stuck, or what spawned it to begin with. I attached VisualVM to see if it would tell me what's going on. The graph is pretty informative, but it doesn't answer my question:
VisualVM shows the threads being created, but they never close. Neither Eclipse or VisualVM tell me any information about where the threads were created or what they're doing.
How do I determine where a thread was created? How do I prevent them from being orphaned like this?
Many Thanks!
EDIT: I've added a screencap of Eclipse's threads tree when I pause the application.