When providing a pause in the program flow, you use Thread.currentThread.sleep(). But this call possibly throws an InterruptedException. It happens very rarely that your code would be interrupted, but it is possible in which case you will not have paused as long as you wished. Also, including the try/catch logic is bulky and distracting. So its good to have utility classes for your application and you may wish to include a ThreadUtils.sleep method as follows:
(more…)
java.lang.ProcessBuilder allows a developer to redirect the stderr and stdout of an external program to the logger. Here’s some code to show how to do that:
(more…)
Use log4j email appenders to notify operations of problems in your application. Below is sample xml code. Be sure to include activation.jar and mail.jar on your classpath. One note, unless you do some coding, out of the box log4j will only send emails for messages logged at ERROR or FATAL even if you specify otherwise.
Also, you should add the hostname to the subject by including ${hostname} in the appender and adding -Dhostname=myhostname as an environment variable passed to the jvm when starting your application.
(more…)
Here are some configuration hints for spring jms. This is backed by activemq jms provider.
A few comments:
(more…)
This was a pain to set up. But here are a few hints for non-transactional configurations.
A few notes about this setup:
(more…)
jconsole is a cool tool part of 1.6 that can be found in <jdk>/bin. You can connect to local running processes or connect to remote applications usually on port 1099. You can monitor CPU, memory, threads. To perform a heap dump, go to MBeans tab > com.sun.management > HotSpotDiagnostic > Operations.
Input a file location plus the file name in p0 parameter. ex. d:\temp\mydumps\heap.dump.out.
To read this dump you’ll use the built in jhat tool. ex: jhat heap.dump.out to browse through class usage.
JavaServiceWrapper is a useful library that allows you to expose a java application as a windows Service. Note: 64bit install of JavaServiceWrapper is not free, you got pay ~75 per server.
JavaServiceWrapper can be monitored via JMX. The following code shows how to expose it through Spring configuration.
<bean id="wrapperManager" class="org.tanukisoftware.wrapper.jmx.WrapperManager" />
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="JavaServiceWrapper:service=WrapperManager" value-ref="wrapperManager" />
</map>
</property>
</bean>
- Start > Control Panel > Fonts
- Click File > Install New Font
- Navigate to the folder with the new fonts
- Select the font
- OK
http://www.myfonts.com/support/help_install_win.html
The code examples on the ActiveMQ and Spring JMS sites use a straightforward jmsTemplate.receive() call. I found this to be very unstable. It would frequently leave orphaned messages in a queue that would never be picked up.
I moved to a DefaultMessageListenerContainer.java and most of my problems were solved. Here’s a sample code:
(more…)
This blog is a simple collection of resolutions to problems I come across in everyday development. This blog is a just a small way to repay the great debt I owe to all the anonymous coders who have posted solutions across forums, mailing lists, blogs, websites and more.
Java, Python, SQL and related technologies are the focus.