Tuesday, February 12, 2013
Use CountDownLatch as a CyclicBarrier
Saturday, February 9, 2013
Potential perf issues with String.substring()
Thursday, January 31, 2013
final Collection in java
An interesting aspect about final Collection that many java developers may not be familiar with is that making a collection final means only the reference cannot be changed but you can add, remove or change an object inside collection.
Example:
private final List<String> names = new ArrayList<String>();
names.add("Name1"); //Allowed
names.add("Name2"); //Allowed
names = new ArrayList<String>(); //Error
Friday, December 28, 2012
Setup yum repository from a linux iso shared on remote windows machine
1. Mount remote windows share on linux system
Following are the steps:
- Login to Linux as root user
- > mkdir /mtn/winshare
- > mount -t cifs //<windows-machine-IP-addr>/<folder-path/ -o username=<user>,password=<pw> /mnt/winshare (For RHEL > 4)
- > mount -t smbfs //<windows-machine-IP-addr>/<folder-path/ -o username=<user>,password=<pw> /mnt/winshare (For RHEL < 4)
2. Extract Files from iso image and create yum repository
- > mkdir -p /mnt/iso/{1,2,3}
- > mount -o loop /mnt/winshare/disk.iso /mnt/iso/1
- > rpm -ivh /mnt/iso/1/Packages/<createrepo-package-name>.rpm
- > cd /mnt/iso
- > createrepo .
- > yum clean all
3. Create yum repository configuration file
- >
vi /etc/yum.repos.d/iso.repo Place following text in iso.repo
[iso] name=My ISO Repo baseurl=file:///mnt/iso
enabled=1 gpgcheck=0 Monday, December 24, 2012
Debug class-not-found exception
Print ClassNotFoundException
A simple problem that I have found many people struggling with – how to print class-path. Following is the line that can be used to print classpath.
Arrays.toString((((URLClassLoader) Test.class.getClassLoader().getURLs()));
This code returns an array list of all jars and directories on the classpath of the classloader.
- Sarang Anajwala
Friday, December 14, 2012
End of Public Updates for Java SE 6
Tuesday, December 11, 2012
Log4j 2.0 - Some important features
public String getUserEmail(int userId) {
19:08:07.061 TRACE com.class.MyClass 10 getUserEmail - entry parms(1)
19:08:07.061 TRACE com.class.MyClass 13 getUserEmail - exit with (User.Email@gmail.com)
public class MyApp {
private Logger logger = LogManager.getLogger(MyApp.class.getName());
private static final Marker QUERY_MARKER = MarkerManager.getMarker("SQL");
public String doQuery(String table) {
logger.entry(param);
logger.debug(QUERY_MARKER, "SELECT * FROM {}", table);
return logger.exit();
}
}
logger.info("User {} has logged in using id {}", username, userId);
logger.info(new LoggedInMessage(userName, userId));
Friday, November 23, 2012
git - tips
- git remote –v
- git remote add <remote branch name> <remote branch url>
- git push <remote branch name> <local branch name>
Thursday, November 22, 2012
Maven - include a lib manually in local repo
Use following command to include a lib manually in local maven repository:
mvn install:install-file -Dfile=./EWSJavaAPIWithJars_1.2.0.jar -DgroupId=local.disk -DartifactId=EWSJavaAPI -Dversion=1.2 -Dpackaging=jar