Login  Register

Re: Using ImageJ in another java pp in the existing jre, and batch mode on linux

Posted by Jared Hodge on Feb 12, 2010; 8:58pm
URL: http://imagej.273.s1.nabble.com/Using-ImageJ-in-another-java-pp-in-the-existing-jre-and-batch-mode-on-linux-tp3689390p3689391.html

OK, based on the lack of responses, and my own testing, I'm thinking the
behavior that I'm after is either not implemented or broken.  It was
actually trivial to fix once I started working on the java itself, so
here are my additions.  Can someone with commit permissions review these
and commit them or respond back to me with any issues:

 

In ij/measure/ResultsTable.java one added line (shown in context):

public void show(String windowTitle) {

    if(IJ.getInstance() == null) return;

    if (!windowTitle.equals("Results") &&
this==Analyzer.getResultsTable())

 

That fixes the issue with the popup results window in batch mode.

Next to fix the issues with reusing the jre, I made the following two
changes:

In ij/IJ.java, one new function:

static void cleanup() {

    ij=null; applet=null; progressBar=null; textPanel=null;

}

 

And I call that function at the end of the run() function in
ImageJ.java:

    dispose();

    if (exitWhenQuitting)

        System.exit(0);

    IJ.cleanup(); //Clear up the references in case anything else is
done in this jvm

}

 

Hope this is helpful.  Thanks.

-Jared

 

 

From: Jared Hodge
Sent: Friday, February 12, 2010 1:36 PM
To: '[hidden email]'
Subject: RE: Using ImageJ in another java pp in the existing jre, and
batch mode on linux

 

After a little more testing, I think this perceived difference in their
behavior may be due to windows being so much slower to start up the GUI
than Linux (at least for my test systems).  It takes about 3 seconds to
start the GUI under windows and about 1 second under Linux.  The macro
I'm running only takes just over a second to complete, and then I guess
the "System.exit" is reached before the GUI even started on Windows.

 

Either way, this seems like a bug, or am I just not doing something
right?  How do I completely suppress the display of the results window?

 

The macro component that seems to be doing the output is run("Analyze
Particles...").  Is this component broken for batch-mode?

-Jared

 

From: Jared Hodge
Sent: Friday, February 12, 2010 10:44 AM
To: '[hidden email]'
Subject: Using ImageJ in another java pp in the existing jre, and batch
mode on linux

 

Hi, I'm new to ImageJ, so forgive me if this has been addressed before.
I have a java application where I am wanting to use ImageJ.  I would
think running it in my existing jre would be the most efficient way to
process lots of images.  I mostly want to just be able to run macros,
which I'm can do by calling ij.IJ runMacro.  The problem is I want them
to run without any feedback to the monitor (similar to -batch, but
actually processing the script I pass in), but runMacro displays a
"results" GUI on the screen.  Also, if I ever construct an "ij.ImageJ"
in my jre to display the GUI, all macros thereafter display even more
stuff on the screen, even if I've closed the ImageJ GUI (until I restart
my application).  Looking at the code a bit, it looks like the run
method which shuts down the ImageJ GUI is not cleaning up the static
references to itself in the IJ object.

 

I've also noticed a difference in the behavior of macros on Windows and
Linux.  On Windows if I run a batch script, no results are displayed to
the screen.  On Linux, the GUI briefly pops up a "results" window, which
I think tends to slow things down as rather annoying.  Is this a bug?
My test case of my application above is on Linux, so I'm not sure if
these are related.

 

Thanks for any help.

-Jared