Login  Register

Re: Purify_ plugin

Posted by Albert Cardona on Apr 27, 2009; 5:38pm
URL: http://imagej.273.s1.nabble.com/Purify-plugin-tp3692764p3692765.html

Michael Doube wrote:
> http://doube.org/plugins.html#purify
>
> I'm working on improving my coding style, so any suggestions you have
> are appreciated.


For multithreading, I discovered about a year ago the Executors,
ExecutorService, Future, and Callable classes that make multithreading
dead-easy.

For example:

ExecutorService exec =
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());

class DoSomething implements Callable<ImagePlus> {
    public ImagePlus call() {
        // generate an image
        ImagePlus imp = new ImagePlus("that", new FloatProcessor(500, 500));
        return imp;
    }
}


Future<ImagePlus> fu = exec.submit(new DoSomething());

// blocks until it's done:
ImagePlus result = fu.get();

result.show();


// when done:
exec.shutdown();

It's very convenient to operate over very large collections of objects
or operations.

Albert

--
Albert Cardona
http://albert.rierol.net