Saturday, May 26, 2012

How to set the custom heap and permgen sizes in JVM?

Use following JVM parameters:

Set heap sizes...
-Xms128m -Xmx512m
Set perm gen sizes...
-XX:PermSize=64m -XX:MaxPermSize=128m

Monday, May 21, 2012

What is the C3P0 library?

A third party library to enable production level connection pooling for hibernate. Following properties can be configured in hibernate configuration file to configure C3P0:
  1. hibernate.c3p0.min_size – Minimum number of JDBC connections in the pool. Hibernate default: 1
  2. hibernate.c3p0.max_size – Maximum number of JDBC connections in the pool. Hibernate default: 100
  3. hibernate.c3p0.timeout – When an idle connection is removed from the pool (in second). Hibernate default: 0, never expire.
  4. hibernate.c3p0.max_statements – Number of prepared statements will be cached. Increase performance. Hibernate default: 0 , caching is disable.
  5. hibernate.c3p0.idle_test_period – idle time in seconds before a connection is automatically validated. Hibernate default: 0
Ref:
http://www.mkyong.com/hibernate/how-to-configure-the-c3p0-connection-pool-in-hibernate/
https://community.jboss.org/wiki/HowToConfigureTheC3P0ConnectionPool

How to get rid of "ora-28000:the account is locked"?

From oracle 10gR2 onwards the db parameter 'FAILED_LOGIN_ATTEMPTS' value has been changed from 'unlimited' to 10. This is unnecessary for a development DB, because it may cause the user account to be locked frequently upon invalid credential input.

To get rid of this we can specify the FAILED_LOGIN_ATTEMPTS to be 'unlimited'.

Login as a system user...

SQL>connect SYSTEM/SYS;

Assuming username is "DEV_USER", we must first find the db profile of it...

SQL>select profile from dba_users where username = 'DEV_USER';

Assuming the returned value is 'DEFAULT', we can change the limit of 'FAILED_LOGIN_ATTEMPTS' for the profile DEFAULT as below...

SQL>alter profile DEFAULT limit FAILED_LOGIN_ATTEMPTS unlimited;

If the account is already locked it can be unlocked as below...

SQL> alter user DEV_USER account unlock; 

Ref:
http://www.xinotes.org/notes/note/717/
https://forums.oracle.com/forums/thread.jspa?threadID=330359

Friday, May 18, 2012

How to run bash commands within Vim?

Use "!" in the Vim command mode...

e.g. :!ls -al

Thursday, May 17, 2012

Why doesn't parsing using SimpleDateFormat produces expected results?

One reason can be...

by default SimpleDateFormat parses strings in a lenient way. However, this may result in unexpected output. And, in occasions where parsing is used as a mechanism of enforcing date format validation, lenient parsing may parse a date which is in an invalid format.

To avoid this, lenient parsing should be switched off as follows:

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
dateFormat.setLenient(false);

Ref: http://ch-express.blogspot.com/2008/03/simpledateformat-is-lenient.html

How to toggle vi and emacs editing modes in bash?

Use command...

set -o <mode>

mode can be emacs or vi

e.g. set -o emacs

Ref: http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-sheet/

Thursday, May 10, 2012

What are the differences of String, StringBuffer & StringBuilder in Java?

String is immutable. Thus, manipulating plain Strings creates lots of garbage objects. But, StringBuffer and StringBuilder are mutable.

StringBuffer and  StringBuilder are essentially same except StringBuffer's methods are synchronized.

So, in a code segment which is accessed by multiple threads, StringBuffer should be used, and in all other situations StringBuilder is the most suitable. String can be used if it is guaranteed that its objects won't be manipulated later. e.g. converting to uppercase.

http://javarevisited.blogspot.com/2011/07/string-vs-stringbuffer-vs-stringbuilder.html