Thursday, June 23, 2011

Add jar folder in classpath

Add a folder containing multiple jar files in the classpath of a java program

java -Djava.ext.dirs=<jarDirectory>

- This works, but watch out, pass the -Djava.ext.dirs= BEFORE -jar – 
- java.ext.dirs will work very different from a normal jar in classpath. It has higher priority and permission which will able to somehow override classes in bootstamp(rt.jar)

Java Memory profiling tools

Some useful tools for memory profiling:

    Free/Open-source Tools: (In order of preference)

-       MAT (Memory Analyzer Tool): http://www.eclipse.org/mat/ (eclipse update site - http://download.eclipse.org/mat/1.0/update-site/)

-       VisualVM: https://visualvm.dev.java.net/ (Comes as part of later versions of JDK1.6)
-       JMAP: https://olex.openlogic.com/packages/jmap

    Commercial Tools: (In order of preference) [Free tools should be good enough to find out major memory leaks]

      -       JProbe
      -       JProfiler
      -       YourKit

Excellent article on memory profiling:
http://olex.openlogic.com/wazi/2009/how-to-fix-memory-leaks-in-java/

Monday, June 13, 2011

Unix - Commands to find disk usage

df: (disk free)
Df –k <directory name>
e.g. df –k . or df –k /
 
du: (disk usage)
The disk usage (du) command shows the size of each file or directory in the current directory:
  y> du -sk * | sort -n
The "s" option returns a summary of a directory's contents (rather than a full listing), and the "k" option shows the output in 1 KB increments (rather than the default 512 byte increments). The sort command lists them in ascending size order, with the largest directory last.

This will show which directory is using your space, "home," "pub," or "mail." (Ignore the "backup" directory; that is for the nightly backup snapshot and does not impact your disk usage.)

  y> du -sk * | sort -n
  6234    mail
  6018    pub
  182819   home
  95045   backup
In this example, the home directory is where most of the space is being used: almost 183 MB.

Unix - Find/Delete n-days old files

Command to Find/Delete n-days old files… Especially useful for cleaning up logs. (if you are not using rolling logs for some reason)

Find n-days old files:
        >> find . -type f -mtime +5

Delete n-days old files:
        >> find . -type f -mtime +5 | xargs rm

MySQL - Enable remote access

mysql>

Run this command:

GRANT ALL PRIVILEGES ON *.* TO USERNAME@IP IDENTIFIED BY "PASSWORD";

        - USERNAME is the username that you would like to create.
        - IP is the public IP address of your remote connection.
        - PASSWORD is the password you would like to use for this username.

You now must flush MySQL's privileges. Run this command:

FLUSH PRIVILEGES;

Run this command to exit MySQL:

exit;