Category: Java

Simulating a connection reset in java

We start with a class that simply creates a server and a client. The server class is configured to accept a connection and then exit, forcing of course, all connections to terminate. The client class connects, then sleeps two seconds…

Is a JMS MessageConsumer truly asynchronous/non-blocking?

Yes. The code tree is as follows: Receive call on the ActiveMQMessageConsumer class, which implements the javax.jms.MessageConsumer interface… public javax.jms.Message receive() throws JMSException { checkClosed(); checkMessageListener(); sendPullCommand(0L); MessageDispatch md = dequeue(-1L); if (md == null) { return null; } beforeMessageIsConsumed(md);…

Predict full CMS collection

((heap * cms fraction) – current heap used (young and tenured)) / growth rate = prediction Sample data from GC log… : 4499906K->310178K(4718592K), 0.2461130 secs] 10382742K->6214227K(12058624K), 0.2469460 secs] [Times: user=2.77 sys=0.03, real=0.25 secs] 2016-10-25T09:41:02.431-0400: 48708.056: [GC 48708.056: [ParNew48708.198: [SoftReference, 0…

Getting memory by thread

This is not perfect, as the heap is shared. However, the documentation indicates that a ThreadMXBean can calculate how much is in use by each. The idea behind this would be to either instrument your code, or use byte code…

JNLP Example

Java Web Start is the technology that allows a user to run java from their local device. The software that is run is loaded from a server via a directive in a JNLP file on the server. It is downloaded…

CRC check on gzip files in HDFS

I am sure there is a more elegant way to do this, but I wanted it done quickly. We had a few files that threw exceptions about the end of the file being reached (CRC failure) for external files underlying…