Archive for the ‘Uncategorized’ Category

Learnings from the Past: Hibernate related Best Practices

Thursday, March 18th, 2010

Back to blogging after a gap of 8 months. I have been working on some cool optimization stuff related to Hibernate. Here is a brief summary of the best practices i have come across on this and past assignments involving Hibernate.

# Practice What? Why? How?
1 Use Lazy Load Don’t load objects until you need to use them. Queries involve lesser joins, so become faster By Using @Lazy annotation for simple attributes and LazyCollection for Collections
2 Use allocationSize>1 for Sequences Use an allocationSize value of 50 or 100 instead of the default allocationSize of 1 Avoids frequent db access to fetch next sequence value By using @allocationSize=50, Hibernate will generate the next sequence values for 50 invocations before hitting the db again.
3 Keep big character/byte fields in a seperate entity Seperate big fields like blob, clob, varchar(500), etc., into a seperate entity called <enityName>Details Avoids time spent in fetching data for these fields on listing screens which do not typically display this information By using a one-to-one mapping with the details object and keeping the direction of association from main->detail
4 Use Hibernate Caching Using Hibernate Second Level cache and Query cache to store frequently used objects/results Avoids hitting the db for frequently used information Turn on Hibernate Second level cache and Quey cache

Internet Connection monitoring script for the GNOME panel

Wednesday, January 14th, 2009

I was having issues with my Internet connection lately. My connection used to drop after using it for a while and the router used to lose the IP address. I decided to write a simple script that would sit on the GNOME panel and tell me the current state of my Internet connection.

I found a Java-GNOME library that would allow me to program for the GTK using Java. I wrote a simple Java program that would connect to www.google.com and check if it can get the content. It would do this periodically (every 10s) with a connection timeout of 5s. If the site is reachable, the program would show a green icon in the notification area. If not, it will show a red blinking icon.

To use it here is what you need to do:

  1. Extract this archive to a scripts sub-directory in your home folder.
  2. In your .profile, add the following lines at the end
  3. #Invoking Internet connection monitoring script
    $HOME/scripts/networkmonitor.sh

Internet Connection is upInternet Connection is up

Just log in again and you should see a green/red icon in your GNOME panel notification area. In case you face any problems try running $HOME/scripts/network_monitor.sh from a terminal and also check the sh file executable permission.