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…
Category: Java
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);…
Simple awk script to print blocked threads
Yet another variation on this theme. This is good because it will allow you to quickly go to the problem thread. #!/bin/awk -f { if ($0 ~ “- locked” || $0 ~ “- waiting to lock”) { s[i++]=$0 } }…
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…
Testing the overhead of creating connections vs using a pool in Weblogic
We had a need to understand the overhead of creating connections versus using a pool. Connection pooling is most beneficial when using very short lived database sessions. If the associated database request takes longer than a few seconds, we needed…
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…
Setting java command line flags when value is default
Just a snippet of how I proved we were setting values to the default. While this has no negative impact, it does result in needless conversations like… “Why did we set that?” “It’s the default, don’t worry about it.” “Really?…
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…