Providing a default exception handling strategy in Java applications
Mar 16th
When writing a Java application you may need to consider how that application should react when an uncaught exception is encountered. Generally, when an exception is not handled, the threads stack trace is printed to the error stream and the throwing thread dies; potentially causing the application to shut down if there are no other [...]
Identifying which processes are using network ports on a Mac
Feb 9th
Typically I’d use netstat’s -o flag to identify the process ID when listing networking activity from a Linux/Unix machine. Unfortunately this option is not available with netstat on Mac OS X.
I recently has a rogue process (I suspected a virus) on my Mac that was creating thousands of connections out to hosting providers. Luckily I [...]
Adding the application name to links in a Web application
Dec 13th
Application servers can run a number of applications. A single Tomcat instance, for example, will create a separate web application for each WAR file it finds in its webapps directory.
The applications will be named the same as their WAR files and can be accessed using URLs that start with that name. For example, to [...]
Identifying number of account logins on Sybase
Nov 3rd
If you quickly need to see how many logins there are for each account in sybase, you can use this query:
select dbname=db_name(dbid),login=suser_name(suid), #connections=count(suid)
from master..sysprocesses
–where suser_name(suid) like '%dblogin%'
group by dbid, suid
order by count(suid)
Quick formatting of Date using a Java String format expression
Oct 19th
For quick reference, this is how you can format a date as:
dd/mm/yyyy at hh:mm:ss
System.out.printf("Date: %1$te/%1$tm/%1$tY at %1$tH:%1$tM:%1$tS%n", new Date());
The % characters mark a placeholders for String content, the 1$ indicates that the first vararg should be used for each placeholder (there is only one varag value supplied), the letter ‘t’ in each placeholder indicates a [...]
Searching for files in an Ant script
Sep 6th
This is a simple technique for determining whether or not files matching a given pattern exist within your project. Unlike the available task, this does not require that you need to know the exact name of the file when creating the build file. It is therefore very useful for checking existence of generated/downloaded artefacts.
I’ll demonstrate [...]
Adding a thread timeout to methods in Java
Sep 1st
When calling a method that could potentially take longer that you’d like to complete, it is possible to write code that will back out after a given time period.
This can happen in numerous circumstances where you’d like an application to maintain a degree of liveness. I’ve used it recently in an application that needed [...]
Count the processors on a Linux server
Jun 2nd
If you need to see how many processors there are available on a Linu/Unix server, use the following command from your shell:
cat /proc/cpuinfo | grep processor
each of the processors will be listed in the output. For example, on a server I use the output looks like this:
processor : 0
processor [...]
Deleting all files over a certain age on a Linux server
May 4th
To delete files on a Linux server that are all over 3 days old, use this:
find /log/ -type f -mtime -3 -exec rm {} \;
This command will find all files in /log over 3 days old and will run the rm command for each of them.
What info can you get from an HttpServletRequest?
Feb 1st
There are many methods on an HttpServletRequest, and if you’re anything like me, you’ll forget exactly what each of them returns. Rather than a long winded investigation into them all, here’s a sample URL:
https://localhost:8443/test/welcome?a=1&b=2
The ‘/test’ in the URL will map to a servlet called test. The servlet will dispatch the request to a JSP for [...]
