Archive

Archive for December, 2008

CRUD Application : Struts 1, Hibernate and MySQL

December 27th, 2008 24 comments

Sample Struts, Hibernate CRUD application with i18n and validation support.

Download the source code leadapp.zip (5.66 Mb)

Building and deploying the application

  • Create a schema/user using the schema.sql  file in src/database
  • Open build.properties and modify “tomcat.home” property to point your tomcat home directory
  • Database username/password can be configured in the hibernate config file \WebRoot\WEB-INF\hibernate.cfg.xml
  • Issue “ant clean deploy” command to build and deploy the application to tomcat.
  • Access the application http://localhost:8080/leadapp  (assuming tomcat is running on 8080 port)
  • username/password is user@javachap.com/javachap

I hosted this application on stax.net, access it from here http://hw4999.dvkvarma.staxapps.net

Application Screenshots

Login Page

Lead Listing Page

Lead Create Page

Categories: Java Tags: , , , , ,

Debugging in Java

December 22nd, 2008 No comments

The Java Debugger

The Java Debugger (jdb) helps you find and fix bugs in Java language programs both locally and on the server. A VM that is to be debugged with jdb must be started with the following options:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000

-Xdebug will instruct the VM to enable debugging support.

-Xrunjdwp <options> will load the JPDA reference implementation of JDWP.

Xrunjdwp Options

  • transport=dt_socket instructs JVM that the debugger connections will be made through a socket
  • address=8000 instructs JVM that the socket will be opened on port 8000
  • suspend=n If configured as ‘y’ the JVM starts in suspended mode and stays suspended until a debugger attaches to it. This is helpful if you want to start debugging as soon as the JVM starts.
  • server=y If “y”, listen for a debugger application to attach; otherwise, attach to the debugger application at the specified address. 

for more options visit http://java.sun.com/j2se/1.4.2/docs/guide/jpda/conninv.html#Xrunjdwp To enable debugging in tomcat set an environment variable called JAVA_OPTS.

set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

View Heap Dump

Hit Ctrl + Break to dump a list of threads and all their held locks to stdout. If your app is stuck, you can figure out what it is doing. If it is deadlocked, sometimes the JVM can even tell you exactly which threads are involved. If you are running the java application as a service then you will need a tool to send a SIGINT signal to the JVM. One such tool is SendSignal

Record heap dump on OutOfMemory

The most common problem that we run into is OutOfMemoryError, this happens when there is memory leakage. By specifying some options we can instruct JVM to take the heap dump when the JVM runs out of memory. The JVM must be configured with following options to record the heap dump

-Xrunhprof:heap=dump,format=b
-XX:+HeapDumpOnOutOfMemoryError

If you don’t want big dump files in the application working directory then the HeapDumpPath option can be used to specify an alternative location, for  example -XX:HeapDumpPath=/disk2/dumps will cause the heap dump to be generated in the /disk2/dumps directory.

Note: To list all available options, use java -Xrunhprof:help

Reference

Categories: Java Tags: ,

Unlimited Online Storage : Livedrive.com

December 21st, 2008 No comments

Livedrive offers users an unlimited online storage.With Livedrive, you get all the normal features: backup, sharing, mobile access and  a web portal to manage and upload your files.

Users running Windows XP/Vista machines are able to download a stand alone client which adds a virtual drive to their computer assigned to the letter L. This means you can just drag files onto your Livedrive like any normal USB drive.

Check out the free Livedrive beta trial here.

Categories: Web2.0 Tags: ,

Rab Ne Bana Di Jodi

December 19th, 2008 No comments

So I saw the movie last night, Rab Ne Bana Di Jodi.

Asusual, Sharukh Khan is superb, your heart goes out to him every time he appears on screen. Anushka has done a pretty awesome job in her dream debut movie. Salim-Sulaiman’s Music is good too, i’m still humming ‘Haule Haule’.

On down side, Wife(Anushka) not able to recognize her husband(Sharukh) after a makeover and not a convincing Climax .

Overall i enjoyed the movie and sharukh’s acting.

Categories: General Tags:

Java over the Cloud

December 19th, 2008 1 comment

I just found this site called Stax Network, http://www.stax.net.

Stax is offering a platform as a service product for Java applications, similar to Amazon EC2. Allows developers to create, test and deploy Java applications very easily. This will be extremely useful for the startups that build there apps on java, without having to build out their own physical infrastructure.

The best part is you can scale the apps on demand from a single shared server to a load-balanced cluster and  you will only pay for the computing resources that you use.

Applied for the beta, Waiting for the key. Its free until it moves out of beta.

Update: Got the invitation code today, tried a sample application, Worked as expected.  The admin UI has few glitches in firefox, but worked fine in Chrome.

Update2: Deployed my sample application i.e. built on top of hibernate/struts and mysql.  No issues while running on single server. But when it is load balanced on 2 servers, running into invalid session error. May be the requests are not sent to the same server. I need to figure this out, will update you on this. Contact me if you want the source code of the sample app. It uses hibernate and struts, db is mysql

You can access the sample app at http://hw4999.dvkvarma.staxapps.net

Categories: Java Tags: ,

Humor

December 17th, 2008 No comments

SE: I’m tired of being SE for last 3 years.I demand my designation to be changed to SSE

HR : Okay, No problem we do everything to keep our employees happy.

……..

HR : SE, your designation has been changed to SSE (Still Software Engineer) – HR

Categories: General Tags: