Java HBase PrivilegedExceptionAction运行方式线程?
我有用于Get的HBase代码(虽然我没有启用Kerberos,但我计划稍后启用它,因此我希望确保在连接和执行Put或Get时正确处理用户凭据) 在这个Java HBase PrivilegedExceptionAction运行方式线程?,java,thread-safety,hbase,Java,Thread Safety,Hbase,我有用于Get的HBase代码(虽然我没有启用Kerberos,但我计划稍后启用它,因此我希望确保在连接和执行Put或Get时正确处理用户凭据) 在这个run()函数中。但是为了从run()线程中获取信息,我在run()之外使用了一个新的字节输出流byteOutputaryStream.write和byteOutputaryStream.flush在run()中。然后toByteArray()从函数中获取HBase内容的二进制字节。这会导致返回空字节,所以可能我做得不对 然而,我很难找到HBas
run()函数中。但是为了从run()
线程中获取信息,我在run()
之外使用了一个新的字节输出流byteOutputaryStream.write
和byteOutputaryStream.flush
在run()中。然后toByteArray()
从函数中获取HBase
内容的二进制字节。这会导致返回空字节,所以可能我做得不对
然而,我很难找到HBase
javaapi的好例子来做这些事情,而且似乎没有人像我一样使用runAs。真奇怪
我让HBase 1.2.5客户端在Web应用程序中运行(基于请求的函数调用)。在这段代码中,线程在“MyHBaseService.getUserHBase().runAs”中运行。但如果它是异步运行的,那么在正确执行它之前,程序将返回“bos.toByteArray();”,因为这在runAs()之外。因此,在执行完整函数之前,它将返回输出
我认为这就是空值的原因。但这就是我的观点。。。。它是异步运行还是同步运行我对缺少HBase API的文档感到非常失望。甚至HBase的书也不完整,缺少这样的例子。
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
MyHBaseService.getUserHBase().runAs(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws Exception {
Connection connection = null;
Table StorageTable = null;
List<hFile> HbaseDownload = new ArrayList<>();
try {
// Open an HBase Connection
connection = ConnectionFactory.createConnection(MyHBaseService.getHBaseConfiguration());
Get get = new Get(Bytes.toBytes("filenameCell"));
Result result = table.get(get);
byte[] data = result.getValue(Bytes.toBytes(MyHBaseService.getDataStoreFamily()), Bytes.toBytes(MyHBaseService.getDataStoreQualifier()));
bos.write(data, 0, data.length);
bos.flush();
...
}
});
// now get the outputstream.
// I am assuming byteArrayStream is synchronized and thread-safe.
return bos.toByteArray();
Get get = new Get(Bytes.toBytes("filenameCell"));
Result result = table.get(get);