Author: billie
Date: Fri May 18 13:31:59 2012
New Revision: 1340090
URL: http://svn.apache.org/viewvc?rev=1340090&view=rev
Log:
ACCUMULO-587 added finalize for batch reader
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReader.java
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReader.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReader.java?rev=1340090&r1=1340089&r2=1340090&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReader.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReader.java
Fri May 18 13:31:59 2012
@@ -36,8 +36,10 @@ import org.apache.accumulo.core.data.Val
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.security.thrift.AuthInfo;
import org.apache.accumulo.core.util.ArgumentChecker;
+import org.apache.log4j.Logger;
public class TabletServerBatchReader extends ScannerOptions implements
BatchScanner {
+ public static final Logger log =
Logger.getLogger(TabletServerBatchReader.class);
private String table;
private int numThreads;
@@ -55,12 +57,17 @@ public class TabletServerBatchReader ext
return nextBatchReaderInstance++;
}
- private int batchReaderInstance = getNextBatchReaderInstance();
+ private final int batchReaderInstance = getNextBatchReaderInstance();
- private class BatchReaderThreadFactory implements ThreadFactory {
+ private static class BatchReaderThreadFactory implements ThreadFactory {
private ThreadFactory dtf = Executors.defaultThreadFactory();
private int threadNum = 1;
+ private final int batchReaderInstance;
+
+ BatchReaderThreadFactory(int batchReaderInstance) {
+ this.batchReaderInstance = batchReaderInstance;
+ }
public Thread newThread(Runnable r) {
Thread thread = dtf.newThread(r);
@@ -80,7 +87,7 @@ public class TabletServerBatchReader ext
this.numThreads = numQueryThreads;
queryThreadPool = new ThreadPoolExecutor(numQueryThreads, numQueryThreads,
60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
- new BatchReaderThreadFactory());
+ new BatchReaderThreadFactory(batchReaderInstance));
ranges = null;
}
@@ -89,6 +96,17 @@ public class TabletServerBatchReader ext
queryThreadPool.shutdownNow();
}
+ /**
+ * Warning: do not rely upon finalize to close this class. Finalize is not
guaranteed to be called.
+ */
+ @Override
+ protected void finalize() {
+ if (!queryThreadPool.isShutdown()) {
+ log.warn(TabletServerBatchReader.class.getSimpleName() + " not shutdown;
did you forget to call close()?");
+ close();
+ }
+ }
+
@Override
public void setRanges(Collection<Range> ranges) {
if (ranges == null || ranges.size() == 0) {