hbase-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ioan Eugen Stan <stan.ieu...@gmail.com>
Subject HTableInterface to extend java.io.Closeable
Date Tue, 10 Jan 2012 10:57:08 GMT
Hello,

In my code I get to write a lot of boilerplate code to close a HTable
instance (see below snippet). Making HTableInterface extent
java.io.Closeable would allow developers to use IOUtils.closeQuietly()
from appache-commons or a similar method to cose a HTable instance
without the extra code. What do you think?

       HTable table = null;
        try {
            table = new HTable(conf , "some table");
            ResultScanner scanner = table.getScanner(scan);
            Result result;
            while ((result = scanner.next()) != null) {
                 // do something
            }
            scanner.close();  // close the scanner
        } catch (IOException e) {
            LOG.error("Exception scanning in table");
        } finally {
         // close the table
            if (table != null) {
                try {
                    table.close();
                } catch (IOException e) {

                }
            }
        }


Cheers,

-- 
Ioan Eugen Stan
http://ieugen.blogspot.com/

Mime
View raw message