Archive for May, 2011

Time portion from your Date / DateTime / Timestamp field getting truncated when using the JDBC ResultSet?

Tags:

Problem – You see that from Date-Time value you are saving into your database, the time part is getting truncated at some point. What on earth is happening? You may notice that if you look at the field in your database, you do see the time being persisted. So infact, it is something you are [...]

Continue reading » 1 Comment

Sending a SIGBREAK signal to a Java process to do a thread dump in Windows

Tags: ,

In Linux / Unix if you want a Java process to do a thread dump, you can do a kill -3 <pid>. In Windows, doing the equivalent requires sending a Ctrl+Break to the input console which results in a SIGBREAK being sent to the process. But what if you do not have an input console? [...]

Continue reading » 1 Comment

Java NullPointerException Ninja – 10 facts you need to know to avoid problems with null

Tags:

1.The instanceof operator is NPE safe. So, instanceof null always returns false. It does not cause a NullPointerException. You can eliminate messy conditional code if you remember this fact. // Unncessary code if (data != null && data instanceof InterestingData) { } // Less code. Better! if (data instanceof InterestingData) { } 2. A null [...]

Continue reading » 6 Comments

Crash your JVM by killing the garbage collector!

Tags: ,

My HotSpot 1.6.0_21 JVM crashes if the following code is run on it. And by “crashes”, I mean that the JVM crashes and leaves an hs_err_pid####.log file with the thread dump from the JVM itself – there is no exception from the application code. class Crash { public static void main(String[] args) { Object[] link [...]

Continue reading » No comments

How to suspend VM on startup when remote debugging your Java app

Tags:

You want to do a remote debugging session on code that runs in the initial few seconds of your app being launched. A problem that you can run into when attempting to do this is that since the code runs right in the beginning, the JVM may rush past it before you have had a [...]

Continue reading » 1 Comment

Assigning a reference to itself in Java has no effect, right? – WRONG!

Tags: , , ,

You see this piece of code in your beloved code base…. referenceToSomethingImportant = referenceToSomethingImportant; You immediately delete it since assigning a variable to itself will never do any thing. Of course the compiler or the JIT machinery is always going to optimize it away anyway. Right? Wrong. Oh yes, there might be another thread you [...]

Continue reading » 1 Comment