I have created a pool of objects that I need to reuse. Every time I try to return the object I get an error of: "Returned object not currently part of this pool"
I have override the both the equals and hashcode methods but that does not help.
I set the pool up using this code:
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxIdle(10);
config.setMaxTotal(10);
config.setTestOnBorrow(true);
config.setTestOnReturn(true);
ImageDownloaderPool.POOL= new ImageDownloaderPool<String, String>(new ImageDownloaderFactory<String, String>(), config);
Here is how I am overriding equals and hashCode:
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ImageDownloader)) return false;
ImageDownloader<String, String> that = (ImageDownloader<String, String>) o;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
return true;
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
I call returnObject on the Pool like this:
finally {
if (dl != null) {
try {
ImageDownloaderPool.getPOOL().returnObject(dl);
}
catch (Exception e2) {
e2.printStackTrace();
}
I get this error:
java.lang.IllegalStateException: Returned object not currently part of this pool org.apache.commons.pool2.impl.GenericObjectPool.returnObject(GenericObjectPool.java:524) com.ifmrestoration.webscraper.CorrigoScraperPool.returnObject(CorrigoScraperPool.java:45) com.ifmrestoration.webscraper.ImageDownloader.saveImageFromAWSurl(ImageDownloader.java:164) com.ifmrestoration.webscraper.ImageDownloaderServlet.doPost(ImageDownloaderServlet.java:49) javax.servlet.http.HttpServlet.service(HttpServlet.java:707) javax.servlet.http.HttpServlet.service(HttpServlet.java:790) org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:848) org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1772) com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60) org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759) org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582) org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524) org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226) org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134) com.google.apphosting.runtime.jetty9.ParseBlobUploadHandler.handle(ParseBlobUploadHandler.java:119) org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1182) com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.doHandle(AppEngineWebAppContext.java:187) org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512) org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112) org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:293) org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134) org.eclipse.jetty.server.Server.handle(Server.java:539) org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:333) com.google.apphosting.runtime.jetty9.RpcConnection.handle(RpcConnection.java:213) com.google.apphosting.runtime.jetty9.RpcConnector.serviceRequest(RpcConnector.java:81) com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:134) com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest(JavaRuntime.java:722) com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest(JavaRuntime.java:685) com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:655) com.google.apphosting.runtime.JavaRuntime$NullSandboxRequestRunnable.run(JavaRuntime.java:847) com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:270) java.lang.Thread.run(Thread.java:748)
Since you are instantiating your pool with two classes i assume you are extending
In that case, you should use:pool.returnObject("yourkey", yourobject);AFAIK override is not needed.