Singleton on a multithreaded environment

Static keyword
Java itself facilitates creation of global single classes using a static key word. But using static classes in concurrency is a disadvantage. When a class is declared as static both class and instance methods use the same object lock. This may lead to deadlocks and competition to acquire a lock. Also static fields instantiate at the state of class loading. This mean static may lead to start-up overheads. Singleton classes guarantee only one instance over the program. Singleton also has several variants. Most of these mechanisms guarantee a single instance in sequence programming which is when only one thread is running, but in concurrent programming it is guaranteed to have multiple threads accessing same singleton class. Singleton can be destined to keep predefined instances over program.

class BarMaid {
 private BarMaid() {
 private static BarMaid uniqueinstance = null;
 public synchronized static BarMaid getuniqueinstance()
   if (uniqueinstance == null)
   uniqueinstance = new BarMaid();
   return uniqueinstance;
Above code shows singleton approach to BarMaid class. But when multiple threads access the class at same time it returns multiple instances.

Lazy Instantiation

A singleton can be designed to avoid situations like above by avoiding lazy instantiation. JVM loads class dynamically. Quality of static keyword is that it executes first and does not internalize until the class load happens dynamically. This will guarantee thread safety of the singleton.
    public class LandLord{
    private static LandLord uniqueinstance = new private LandLord() {}
      public static LandLord getuniqueinstance() {
      return uniqueinstance;


Don't always remember good things you have done to others. But always remember bad things you have done to the world.

Write things you learn

I am a hard worker and a good technical reader. With experience and the framework of undergraduate life I understood one thing, "Always write what you learn". Then you can refer them without wasting time on Google for the same thing you have done once.
When you don't have a touch or practice of things you learn there is high possibility for you to forget things. This is the reason most of technical people maintain a blog of their thoughts and day to day activities of life.

Tomcat configuration

Add users to manager -GUI

Tomcat manager- is to administrate Tomcat. At the first step of using it we need to create Tomcat Administrator accounts (i.e manager, admin).

To do this, open /conf/tomcat-users.xml with your favorite editor and add the following lines.
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="admin" password="tcpass" roles="admin,manager"/>


Moving to Arch Linux

Life always needs a change and I always change my linux destro. So now I am officially an Arch user.

Taking about my linux experience as non geek I have used most of the popular linux operating systems at least for a day ;). I was plannig to work on moving to Gento as soon as I got a leasure time .

Mean while my geek friend sam explained me his experience on Arch. All plans changed and decided to try Arch before Gento. I never thought I would start to love Arch this much.

Arch wiki is extremely good and has documented most of the Arch related stuff very well. It has a smart comparison on other  Beginner-friendly , General , The *BSDs ,Source-based and Minimalist linux destros.

Gentoo is  always good for self optimization. But problem arise when it come to compilation. According to the above described comparison , Gentoo is a source based destro .So that mean have to self compile .This compilation may take considerable amount of time (some times hours ;) ).  
Arch comes compiled and optimized for hardware. Thinking about the facts and the value of time and the nature of Sri Lanka electricity I decided as it is always good to try Arch instead of Gentoo. Also at the end most of the time both does the same work as a minimalist distro. It gives you full handle for high level OS customization. Both are rolling distro which mean you always keep your OS up-to-date with the latest version of software by using its smart package manager .

Arch comes as two formats Netinstall Image (184 MB) and Core Image (340 MB). I continued with core installation since my internet connection is pretty slow (512). Installation was very fast and got the terminal within a few minutes. Then after installing X window system, any open source Window Manager (WM) or Desktop Environment (DE) can be selected. I  installed Xorg as my X window system and gnome and after that i shifted to KDE.

Using rc.config basic system configurations can be easily configured. It has a deamon array and module array which allows users to configure what to load what not to load . My laptop uses broadcom B43 kernel driver and by default it does not load automatically sometimes. I had this issue in Ubuntu too . But since I am the one configuring my OS what I had is to simply include it in rc.config file. This can be done for Window Manager as well.

Finally Arch Linux is very good for people who need to get knowledge about your operating system and need fun using it. I am sure you will love it more over other linux destros.

Pseudo Code to Find Minimum Spanning Tree Using Brute Force

Pseudo Code to Find Minimum Spanning Tree Using Brute Force

Pseudo code to find Minimum Spanning Tree using KRUSKAL’S ALGORITHM

Pseudo code to find Minimum Spanning Tree using KRUSKAL’S ALGORITHM

Mount NTFS on boot and give read write perssion for normal users

Step 1 - Install ntfs-3g package
              #sudo pacman -S ntfs-3g
step 2 - open /etc/fstab
              #sudo nano /etc/fstab
step 3 - add following line
     /dev/sda5 /media/ntfs1 auto  gid=users,fmask=113,dmask=002 02

Remove Arch Linux pacman lock

Following is a common situation occurring when you try to stop pacman processes by-force. 
failed to init transaction (unable to lock database)
if you're sure a package manager is not already
running, you can remove /var/lib/pacman/db.lck

A working Solution for this is

rm -r /var/lib/pacman/db.lck

source :