session.getUserProperties().put(
"org.apache.tomcat.websocket.BLOCKING_SEND_TIMEOUT",
Long.valueOf(SEND_TIME_OUT_MILLIS));
Basic remote = session.getBasicRemote();
remote.setBatchingAllowed(true);
for (int i = 0; i < MESSAGE_COUNT; i++) {
remote.sendText(MESSAGE);
}
// Ensure remaining messages are flushed
remote.setBatchingAllowed(false);
}