You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@nutch.apache.org by Žygimantas Medelis <zy...@medelis.lt> on 2010/11/06 21:51:27 UTC
Shared objects between plugin instances
Hi,
Nutch initializes plugins multiple times and so
any expensive initialization procedures are being executed more than once.
For example plugin needs to make a connection to the data base. Each
instance of the plugin will have to create that connection, which leads to
plugins spending lots of time making connections (I'm using db connections
only as an example). Ideally a connection pool must be created and shared
between instances of a given plugin.
Is there any way to share objects (e.g. connection pools) between instances
of the plugin?
JavaDoc for org.apache.nutch.plugin.Plugin states:
"A possible usecase of the <code>Plugin</code> implementation is to
create or close a database connection."
I have tried this code in Plugin's startUp code:
((MyPlugin)
getDescriptor().getExtensions()[j].getExtensionInstance()).setExpeciveStuff(
x );
but calling getExtensionInstance leads to StackOverflowException
Regards,
zm
Re: Shared objects between plugin instances
Posted by Andrzej Bialecki <ab...@getopt.org>.
On 2010-11-06 21:51, Žygimantas Medelis wrote:
> Hi,
>
> Nutch initializes plugins multiple times and so
> any expensive initialization procedures are being executed more than once.
> For example plugin needs to make a connection to the data base. Each
> instance of the plugin will have to create that connection, which leads to
> plugins spending lots of time making connections (I'm using db connections
> only as an example). Ideally a connection pool must be created and shared
> between instances of a given plugin.
>
> Is there any way to share objects (e.g. connection pools) between instances
> of the plugin?
Yes - use the ObjectCache utility class. It's basically a singleton
instance of a map, where you can keep objects that will be alive as long
as the JVM is alive.
--
Best regards,
Andrzej Bialecki <><
___. ___ ___ ___ _ _ __________________________________
[__ || __|__/|__||\/| Information Retrieval, Semantic Web
___|||__|| \| || | Embedded Unix, System Integration
http://www.sigram.com Contact: info at sigram dot com