Category: Java

Does BlockingQueue.take() use CPU?

No… [root@cmhlcarchapp01 ~]# cat t.java import java.util.concurrent.*; public class t implements Runnable { static ArrayBlockingQueue Q = new ArrayBlockingQueue(5); String type; public static void main (String args[]) { t n = new t(“producer”); t n2 = new t(“consumer”); } public…

Listing all queues in ActiveMQ

This still has an issue with getting a consistent read. I will update this once I figure that piece out… import org.apache.activemq.*; import java.util.*; import org.apache.activemq.advisory.DestinationSource; import javax.jms.*; import javax.naming.*; import org.apache.activemq.*; import org.apache.activemq.command.ActiveMQQueue; public class ListQueues { public static…

Improving batch inserts into MySQL

We had a custom class to copy data from Oracle to MySQL at AWS. It was sending each statement individually, even though we batched them. import java.sql.*; public class test { public static void main(String args[]) throws Exception { Class.forName(“com.mysql.jdbc.Driver”);…

Good java decompiler

I had a need to find all classes that exposed a REST based interface. I couldn’t figure out how to do this with jd-gui, so this will be my new go-to for decompiling… https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler $ for f in $(find .…

Programatically gathering a thread dump

This is just a method you could add to your software if you wish to trigger a thread dump in a controlled fashion. import java.sql.*; import java.lang.management.*; public class DebugLocks { public static String dumpThreads() { final StringBuilder dump =…

Java garbage collection stats

jstat -gcutil -t 18987 1000 where 18987 is the java PID, and 1000 is the number of milliseconds (1 second) between samples 896794.7 0.00 0.00 4.01 5.63 98.94 9259 282.051 250 336.211 618.262 896795.7 0.00 0.00 5.31 5.63 98.94 9259…

Unexpected end of file from server

The “java.net.SocketException: Unexpected end of file from server” exception is thrown in the HTTPClient class, as well as others. This article simply provides an example of how to generate it for testing purposes. We start with a client class that…