Java performance tips…. cover story

i have been working on performance improvement and memory leak issues and it was a interesting journey and gave me lots of insight that i never thought it was so deep. Every single line of code you write contributes to the performance and making right choices in your design and DB connections adds to that as well. It was a refreshing thought process and hope i will more on these of things.

OK, so much speaking. let me get it straight to the point. I want to document my thoughts and insight so i will remember and i use this learning as a reference in future.

Below are 3 things which will help us when put together

1. Thread Dump

2. GC Dump (Garbage Collection Dump)

3. Heap Dump

Okay what are these. Dumps are nothing but a snapshot. So

1. Thread Dump – Snapshot of threads or process currently present and its state at the given moment of time.

2. GC Dump – Snapshot of Garbage Collection activity. (Reading more how garbage collection works gives you a good insight. let me post that as well next.)

3. Heap Dump – Shapshot of heap space , memory activity and tells about the retained heap space and this actually shows us if there any memory leaks.

search & copy in linux CLI

im not that familiar with Linux CLI. So i struggle a lot for doing anything here.

so this is one among them.

i need to search for files which are in different directories and copy them all to a new directory.

sounded pretty simple to me and i tried using xargs notation. failed terribly!!

i did something like this

find ./ – name *.ogg | xargs cp /tmp

above one failed coz my filename had spaces in them.

so i moved on to use -exec to execute the command output. failed.

so here is what i did . this one worked . perfecto

find ./ -name *.ogg -type f -exec sh -c ‘exec cp -f “$@” /Music/diir’ X ‘{}’ +

felt glad.

what does inverse=”true” means in Hibernate ?

I want to keep it simple. just for the clarity purpose.

Inverse defines which side is responsible of the association maintenance.
The side having inverse=”false” (this is the default value) has this responsibility.

As a general rule, in a bidirectional relation, one side must set inverse to true, that owns the responsibility for the relationship.

References:
http://www.barneyb.com/barneyblog/2010/04/09/dont-forget-inverse-true/

http://blogs.warwick.ac.uk/colinyates/entry/hibernates_bizzare_interpretation/

http://stackoverflow.com/questions/1012874/hibernate-unidirectional-parent-child-relationship-delete-performs-update-on

Please read the hibernate docs for more depth in this topic.

Flash Video appearing Blue in Ubuntu – Fix

This link is very comprehensive with workarounds and multiple solutions 

http://askubuntu.com/questions/117127/flash-video-appears-blue

Personally for me did update the patch below ( mentioned in that link as well)

sudo add-apt-repository ppa:tikhonov/misc
sudo apt-get update
sudo apt-get install libvdpau1

this works great for me. Just restart after the update. 

Was looking for this solution for long time and here it comes. 

 

Installing javac in ubuntu

rammy@rammy:~$javac

The program ‘javac’ can be found in the following packages:
 * openjdk-6-jdk
 * ecj
 * gcj-4.4-jdk
 * gcj-4.6-jdk
 * gcj-4.5-jdk
 * openjdk-7-jdk
Try: sudo apt-get install <selected package>

I see javac is not installed with the openJDK and we have to run this manually

sudo apt-get install openjdk-7-jdk

Now it works 🙂 i am able to access the javac anywhere.

** There can be a catch that sometimes a symlink will be not created automatically you might need to create it manually. I never faced it but still i am sharing what i read.

 

youtube-dl >>> download youtube videos & rip music. Game on!!!

i was looking for something which will help me in downloading the videos and mainly ripping mp3 out of videos. Moving to linux full time as its advantages. I get to find something cool everyday and lot of LITs (Learned It Today) 

So coming to the tool – youtube-dl , its interesting and got what i was looking for. 

 

Step 1: Install the youtube-dl or get the youtube.dl.sh. either way will do.

sudo apt-get install youtube-dl 

Step 2: Install the ffmpeg for extra drivers which are required for mp3 rips.

sudo apt-get install ffmpeg libavcodec-extra-53

Step 3: Now below command will do the trick of ripping of mp3 from the video. Happy converting….

youtube-dl –extract-audio –audio-format=mp3 -t <youtube-url>

I now love this stuff.

 

 

 

Installing mysql server & GUI in ubuntu 12.04 LTS

1. Open up terminal and enter the below command
sudo apt-get install mysql-server

2. During installation, you will be prompted for password for mysql root user.

3. Once installation is complete, to check whether installation was successful, enter the below command
sudo netstat -tap | grep mysql

you will see output something like

tcp        0      0 localhost:mysql         *:*                     LISTEN      9773/mysqld 

4. If server is not running properly, enter the command to restart the server.
sudo /etc/init.d/mysql restart

SO NOW MOVING ONTO INSTALLING GUI CLIENT FOR MYSQL SERVER

Its simple , we need to add the repository.

sudo add-apt-repository ppa:olivier-berten/misc
sudo apt-get update
sudo apt-get install mysql-workbench-gpl

so this will install the repository & you update the repository and install the workbench.

MySQL workbench replaces the MySQL Query Browser and MySQL Adminstrator.

So with this we have installed MySQL.

Basic coding standards for JSF + Richfaces

I never found a comprehensive standards that developers can adhere or follow or use as guideline or points to remember when designing the UI screens using JSF + richfaces. Its interesting that some well defined standards are not available for UI side in java technologies or atleast I didnt find any.

So here are some guidelines which for picking using JSF & Richfaces

1. Understand the current system or the system you are going to create using the JSF.

2.  Understand the JSF lifecycle, without which any design we arrive will not be using JSF potential.

above 2 i think is very important for kickstart the JSF design in the first place and this is also gonna help us in development effort.

okay now going into the dev standards which i believe and followed when working with JSF & richfaces.

1. Dont use any tag unless you know what it translates to and whats its purpose.

(e.g) <h:panelGrid> translates to html table. so really think you have table used there or  div will do.

<h:panelGroup layout=”block” /> will be rendered as div & without layout attribute it will be rendered as span.

2.  Dont use rich tags when you can use simple JSF tag. <a4j> and <rich> tags when rendered comes with html component with added javascript/images/css and over which its difficult to have complete control ( though there are ways) but its very complicated than necessary and it also takes more time to render.

3. When designing the UI pages stop using “style” (inline styling) attribute and start using “styleClass”.

4. When we have error messages to be displayed next to the component or any custom messages to be displayed next to component, we will see some kind of jumping of the components when the message gets displayed. This is due to message suddenly appears and takes up some space to display the text. Avoid this by creating a placeholder for the messages as well. I mean when designing the UI page provide a static space for the <h:message> or <rich:message>

5. To simplify the dev effort we might easily use the <a4j:commandButton> or <a4j:commandLink> , may be we want to display a modal pop up without having to refresh the page or posting the page. But this will create what we discussed in point 2, it will add javascripts, images and CSS which are not required for this purpose.  For this we can use <h:commandButton> and add <a4j:support>. simplifies the effort.

6. Try to have more control on CSS, this helps us to have external designer come in and create style classes. This makes the page more stable and styled which gels well with our JSF framework.

7. <a4j> and <rich> component comes with attribute called “ajaxSingle” which by default is false. Understand this attribute and make it to true. It will help us a big deal when we dont need all the elements submitted for validation.

8. Always create custom converter for the object to use those objects/entities directly in the page. This will avoid the additional view beans being used.

9. Design the Backing beans first and then the UI page. This helps us on the long run. Minimize the session scope objects and try keeping most in request scopes. Decide what to go in the session and what not. Getting the sign off on this and let stakeholders understand whats the backing bean design is about.

10. Last but not the least, this is pretty important that you keep the faces-config.xml for understanding our application design. It should be more like a site-map of a website. All the resource bundles, list, converters, validators, bean dependency injections all should be depicted in the faces-config.xml.

These are something i think is useful when deciding when developing. These are usual use cases i have seen in the applications. Most of all is POC before starting the application and best practices for that applications helps developers. Standards should be developed before starting the development.

One more suggestion when designing the UI framework is hide the core technical implementation from the developers so they dont mess with that and this will help the development effort to be fast. Easier said than done, so every project is unique and has its own requirements so please design with solution oriented and scalability in mind. We should be ready for changes in design but with minimal changes.

If anyone got any other points please……

How to run the commands in remote machine

I got into a situation where i have to run some commands in remote machine of my friend. I was looking for creating a thread dump for performance tuning and looking at the options. I liked PSTools. below is one sample they way you can use it.

It will run the jstack.exe in the remote machine and outputs the file to your local ( from where you run this command in cmd prompt)

more details on performance tweaks and tips later 🙂

jdk provides  – > jstack,jconsole ( get the java process id)

any specific questions post it

 

 

 

 

 

psexec \\remotemachinename -s “c:\jdk1.6.0_24\bin\jstack” PID> <logname>.log