例外をデータベースに記録する必要があります。データベース API は、値を ByteBuffer または byte[] 配列として渡すことができると述べています。では、どちらがより効率的ですか?
private final static byte[] getThrowableStackTraceBytes(Throwable throwable) {
StringWriter throwableStackTraceStringWriter = new StringWriter();
throwable.printStackTrace(new PrintWriter(throwableStackTraceStringWriter));
return throwableStackTraceStringWriter.toString().getBytes();
}
対。
private final static ByteBuffer getThrowableStackTraceByteBuffer(Throwable throwable) {
ByteArrayOutputStream throwableStackTraceByteArrayOutputStream = new ByteArrayOutputStream();
throwable.printStackTrace(new PrintStream(throwableStackTraceByteArrayOutputStream));
ByteBuffer throwableByteBuffer = ByteBuffer.wrap(throwableStackTraceByteArrayOutputStream.toByteArray());
return throwableByteBuffer;
}
ByteBuffer を使用すると、特にデータベース メソッドに渡された後に処理される場合に、全体的な操作がより効率的になると思います。私は正しいですか?
(具体的には、例外を Hypertable に記録する必要があり、Thrift Java API を使用します。)