class RequestMessage{
public byte[] getMsgAsBytes() throws UnsupportedEncodingException{
ByteBuffer reqBuffer = ByteBuffer.allocate(PAYLOAD_SZ);
reqBuffer.put(xxx);
reqBuffer.putInt(xxx);
reqBuffer.put(xxx);
reqBuffer.position(0);
return reqBuffer.array();
}
}
The RequestMessage class is then used by a singleton in the following manner(read-only)
.The singleton would be accessed multiple threads in tandem.
private void sendRequest(...) throws Exception {
RequestMessage reqMessage = new RequestMessage( );
gateway.sendAsyncMessage(...., reqMessage.getMsgAsBytes());
}
Is this usage of bytebuffer thread-safe?
We do see occasional corruption of the array contents ,and need to ascertain the casue for that.