incubator-droids-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Javier Puerto (JIRA)" <>
Subject [jira] Created: (DROIDS-68) HandlerFactory fails with multithreaded implementation
Date Thu, 12 Nov 2009 16:19:39 GMT
HandlerFactory fails with multithreaded implementation

                 Key: DROIDS-68
             Project: Droids
          Issue Type: Bug
          Components: core
         Environment: Ubuntu 9.04 i386
Java Runtime 1.6_16
            Reporter: Javier Puerto
            Priority: Critical

Hi, I'm working with Droids and made some URL crawlers to save a lot of web pages in disk.
In JUnit test, I run a little http server and crawl 20 pages, the most times everything works
ok but in rare cases I get an error. I found the problem in the HandlerFactory implementation,
in the example the call to handlers is like this:

protected void handle(ContentEntity entity, Link link)
    throws DroidsException, IOException
  droid.getHandlerFactory().handle(link.getURI(), entity);

If two or more workers is trying to handle at same time, the HandlerFactory will handle with
the same instance. The solution could be saving memory or improving performance.

The first solution could be implemented adding a "synchronized" to HandlerFactory.handle like

public synchronized boolean handle(URI uri, ContentEntity entity)
    throws DroidsException, IOException {
  for (Handler handler : getMap().values()) {
    handler.handle(uri, entity);
  return true;
This solution works but it is a workaround.

The real solution was discussed in the dev list and it was make the Droid and the GenericFactory
abstractions clonable and invoking the clone method in the Worker's constructor.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message