How to optimize your travel site – NOT!

Category: Uncategorized

I recently booked tickets from a certain travel site. As soon as my booking was done, I received an SMS with details about my booking. I also noticed that a pop-up window had been launched on my system. And that window had an interesting URL. http://someSMSGateway.com/blah/foo.php?username=abc&pass=pqr&mobile=9890123456&message=theMessageIGotAsAnSMS – So, the brilliant programmers for that site decided […]

Continue reading » 1 Comment

6 things to remember about saving memory with the String.intern method

Category: Uncategorized

Imagine that you have a flat file in csv format. And it has a 100 million rows from which you are about to read data to store and process in your app. The data is in the format (orderId, storeIdentifier, amountDue). What optimization can you do here? Note that the storeIdentifier is going to be […]

Continue reading » 2 Comments

Using -Xss to adjust Java default thread stack size to save memory and prevent StackOverflowError

Category: Uncategorized

Every thread created in a Java program has its own stack space. The stack space used is not allocated from the heap. Infact if you look at the OS report on the memory used by your JVM, you may notice that it is more than what -Xmx parameter specifies. This is because, beside other things, […]

Continue reading » 8 Comments

Type inference – Generics magic for initializing collections in every project

Category: Uncategorized

The usual syntax for initializing collections in Java is long and boring. The JDK has a type inference feature that makes the task easier. Such methods should probably have been provided with the JDK in the first place. You can add such methods to a Util class in your application for each type of collection […]

Continue reading » 2 Comments

There is a difference between free space and usable space!

Category: Uncategorized

You are working on Java code that involves checking if there is enough disk space available to your Java app to complete some task. You look at the File class for ways to do this. You notice the getFreeSpace() method. And you use it to do your checks for the disk space. Voops! That may […]

Continue reading » Comments Off on There is a difference between free space and usable space!

ConcurrentHashSet in Java from ConcurrentHashMap

Category: Uncategorized

Problem While you do have a ConcurrentHashMap class in Java, there is no ConcurrentHashSet. Solution You can easily get a ConcurrentHashSet with the following code – Collections.newSetFromMap(new ConcurrentHashMap<Object,Boolean>()) Notes A Set lends itself to implementation via a Map if you think about it. So can actually just use a Map. But that may not fit […]

Continue reading » 1 Comment

VirtualMachineError is parent of OutOfMemoryError and StackOverflowError

Category: Uncategorized

Today I noticed that the infamous OutOfMemoryError and StackOverflowError classes are not directly descended from the Error class. Rather, they descend from VirtualMachineError – “Thrown to indicate that the Java Virtual Machine is broken or has run out of resources necessary for it to continue operating.” Nothing terribly useful. But good to know nonetheless for […]

Continue reading » Comments Off on VirtualMachineError is parent of OutOfMemoryError and StackOverflowError

Use binary diff tools like xdelta, bsdiff/bspatch to transfer large files

Category: Uncategorized

What do you do if you have to frequently transfer large files over a slow connection as part of your work? Perhaps new builds produced by your corporate build server need to be deployed at a different location for the QA team? I have seen such scenarios causing huge amounts of wasted time for multiple […]

Continue reading » 4 Comments

Eclipse tip: Add a short cut key to Skip All Breakpoints

Category: Uncategorized

Eclipse doesn’t have a short cut key bound by default to the ‘Skip all breakpoints’ functionality. Here is how you can set one. While you are at it, you probably want to define a few more shortcuts to functionality you use frequently. In Eclipse, go to Window > Preferences > Type in ‘Keys’ in the […]

Continue reading » 4 Comments

/dev/random vs /dev/urandom

Category: Uncategorized

If you want random data in a Linux/Unix type OS, the standard way to do so is to use /dev/random or /dev/urandom. These devices are special files. They can be read like normal files and the read data is generated via multiple sources of entropy in the system which provide the randomness. /dev/random will block […]

Continue reading » 1 Comment

HibernateException – A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance

Category: Uncategorized

The logged exception org.hibernate.HibernateException – “A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance: com.onkarjoshi.hibernate.test.Person.children” Your likely problem Looks like you have a Parent entity and a Child entity. The Parent has a collection of Child entities with cascade=”all-delete-orphan”. You are setting a new collection via the setter thus leaving the […]

Continue reading » 28 Comments

Garbage Collection, Reference types and Reachability – Strong, Soft, Weak, Phantom, Unreachable

Category: Uncategorized

The Java Virtual Machine has 5 different levels of reachability for an object. Strongly reachable An object is strongly reachable if it can be reached by some thread without traversing any reference objects. A newly-created object is strongly reachable by the thread that created it. This is the reference you know about and use all […]

Continue reading » 2 Comments

Blocked thread with Read Write Lock due to writer starvation

Category: Uncategorized

Here is an interesting and simple example of how you can end up with a locked thread in your application and what you can do to avoid it. Task A – Starts at t = 0. Takes a read lock. Runs for 3 seconds. Scheduled to run every 5 seconds. Task B – Starts at […]

Continue reading » 1 Comment

Patni walk-in ad on Facebook

Category: Uncategorized

Patni Computer Systems is a large IT services company and operates out of several locations in India. A few days back Facebook decided to show me this ad for walk-in interviews. Nothing unremarkable about it except that it is probably the first IT company ad that I saw on Facebook. Interesting. Many people fill in […]

Continue reading » 2 Comments

Spring Transaction advice : AOP proxy vs AspectJ weaving

Category: Uncategorized

You are using Spring Transactions with Annotations. MyBS.methodRequired has Required propagation. MyBS.methodRequiresNew has Requires_New propagation. … methodRequired (…) { … methodRequiresNew(…); … } Do you get a new transaction if you call methodRequiresNew from methodRequired? You don’t! Not if you are using the default proxy mode via AOP proxies through which transactional advice is applied. […]

Continue reading » 1 Comment