zSelector not closed

imagej1
imagej
#1

Hi there,

I’m using ImagePlus in an external just to display some images.
When I open ImagePlus and close it I still get a zSelector thread that is not properly destoyed.

In the code I found, I see that StackWindow open a Thread labelled zSelector
But I didn’t find anywhere where this thread it closed.

this class is extended from ImageWidow which recieve the close listener, it call the dispose() but didn’t find anywhere it could close the zSelector thread.

Isn’t there something missing to properly close this thread when the imagewindow is disposed ?

I guess this is in the scope of @Wayne as it involve IJ1,

Best regards,

Salim

0 Likes

#2

Hi there,

No answer for this question ?
Also another way would be to make a public getter to the protected Thread thread of the StackWindow
This way I can interupt this thread at closing using an ImageListener.

To me the cleaner way would be to override the windowClosing method of ImageWindow to interupt the Z-Selector Thread in case of exiting a StackWindow object.

Salim

0 Likes

#3

I cannot reproduce your issue. When looking at Plugins > Utilities > Threads before opening, after opening and after closing the Bat Cochlea Volume sample image, I get the following:

  • before opening:
Thread Group: system  Max Priority: 10

    Thread: Reference Handler  Priority: 10 Daemon
    Thread: Finalizer  Priority: 8 Daemon
    Thread: Signal Dispatcher  Priority: 9 Daemon
    Thread: AppKit Thread  Priority: 5 Daemon
    Thread: Java2D Queue Flusher  Priority: 10 Daemon
    Thread: Java2D Disposer  Priority: 10 Daemon
    Thread: AWT-Shutdown  Priority: 5
    Thread: TimerQueue  Priority: 5 Daemon
    Thread Group: main  Max Priority: 10

        Thread: Timer-0  Priority: 5 Daemon
        Thread: AWT-EventQueue-0  Priority: 6
        Thread: DestroyJavaVM  Priority: 5
        Thread: Threads  Priority: 4
    Thread Group: InnocuousThreadGroup  Max Priority: 10

        Thread: Common-Cleaner  Priority: 8 Daemon
  • after opening:
Thread Group: system  Max Priority: 10

    Thread: Reference Handler  Priority: 10 Daemon
    Thread: Finalizer  Priority: 8 Daemon
    Thread: Signal Dispatcher  Priority: 9 Daemon
    Thread: AppKit Thread  Priority: 5 Daemon
    Thread: Java2D Queue Flusher  Priority: 10 Daemon
    Thread: Java2D Disposer  Priority: 10 Daemon
    Thread: AWT-Shutdown  Priority: 5
    Thread: TimerQueue  Priority: 5 Daemon
    Thread Group: main  Max Priority: 10

        Thread: Timer-0  Priority: 5 Daemon
        Thread: AWT-EventQueue-0  Priority: 6
        Thread: DestroyJavaVM  Priority: 5
        Thread: zSelector  Priority: 4
        Thread: Threads  Priority: 4
    Thread Group: InnocuousThreadGroup  Max Priority: 10

        Thread: Common-Cleaner  Priority: 8 Daemon
  • after closing:
Thread Group: system  Max Priority: 10

    Thread: Reference Handler  Priority: 10 Daemon
    Thread: Finalizer  Priority: 8 Daemon
    Thread: Signal Dispatcher  Priority: 9 Daemon
    Thread: AppKit Thread  Priority: 5 Daemon
    Thread: Java2D Queue Flusher  Priority: 10 Daemon
    Thread: Java2D Disposer  Priority: 10 Daemon
    Thread: AWT-Shutdown  Priority: 5
    Thread: TimerQueue  Priority: 5 Daemon
    Thread Group: main  Max Priority: 10

        Thread: Timer-0  Priority: 5 Daemon
        Thread: AWT-EventQueue-0  Priority: 6
        Thread: DestroyJavaVM  Priority: 5
        Thread: Threads  Priority: 4
    Thread Group: InnocuousThreadGroup  Max Priority: 10

        Thread: Common-Cleaner  Priority: 8 Daemon

This is on Mac OSX with an up-to-date Fiji installation.

0 Likes

#4

In fact i’m using ImagePlus and StackWindow outside Fiji in my own java app.

In the StackWindow there is a close() mehode that work well, it stop the zthread.

Problem is the windowlistener implemented in the parent ImageWindow class only call the dispose() without calling the close() method redified in the StackWindow class.

There is a IJ instance check that call the close in a macro but the else don’t call the close()

if (ij!=null) {
			WindowManager.setCurrentWindow(this);
			IJ.doCommand("Close");
		} else {
			dispose();
			WindowManager.removeWindow(this);
		}

For my app I can solve the problem by using a CustomStackWindow object that extends the StackWindow and redifine the windowClosing to call the close() methods to stop the z-thread.

public class Custom_StackWindow extends StackWindow {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Custom_StackWindow(ImagePlus imp) {
		super(imp);

	}
	
	@Override
	public void windowClosing(WindowEvent e) {
		close();
		super.windowClosing(e);
		
	}
	

}

So technically I can fly but it may be a good weekness to solve by implementing this windowClosing definition in the StackWindow to collect the Z-thread even when this class is opened outside Fiji/ImageJ

Salim

1 Like