Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Sunday, December 4, 2011

Classic Singleton example

A classic and fool-proof example of Singleton sample is as follows,

Considering that we need to create a singleton for an Employee object(some POJO, for easier understanding), a Singleton can be expressed as,

class SampleSingleton{
private static Employee empObject= new Employee();
public static Employee getEmployee(){
return empObject;
}
}

On start up, I create a singleton object and assign it to the empObject, and each time I only send that single object to the caller.

Thursday, August 4, 2011

Deadlock via Threads sample

A sample demonstration of deadlock.
Here it goes.

public class DeadlockSample {

public static void main(String[] args) {
final DeadlockSample d = new DeadlockSample();
final DeadlockSample d1 = new DeadlockSample();
Thread t1 = new Thread() {
public void run() {
System.out.println("Thread t1 before entering synchronized block d");
synchronized (d) {
System.out.println("Thread 1: locked d");

try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
System.out.println("Thread t1 before entering synchronized block d1");
synchronized (d1) {
System.out.println("Thread 1: locked d1");
}
}
}
};

Thread t2 = new Thread() {
public void run() {
System.out.println("Thread t2 before entering synchronized block d1");
synchronized (d1) {
System.out.println("Thread 2: locked d1");

try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
System.out.println("Thread t2 before entering synchronized block d");
synchronized (d) {
System.out.println("Thread 2: locked d");
}
}
}
};
t1.start();
t2.start();
}
}

On execution,

Thread t1 before entering synchronized block d
Thread 1: locked d
Thread t2 before entering synchronized block d1
Thread 2: locked d1
Thread t1 before entering synchronized block d1
Thread t2 before entering synchronized block d

and the program goes into a deadlock. Each Thread waits for the other to complete.

Wednesday, February 16, 2011

JDK, Ant and Tomcat6 installation in ubuntu

Hi,

Before a new installation is to be done, I prefer to un install the previous versions.

Open your Terminal(alt + shift + T) and do the following

first remove any previous versions of java using the

"sudo apt-get remove sun-java6-" command.

Than to install a new version of java,

type in

"sudo apt-get install sun-java6-jdk"

Type Y if prompted for Do u want to continue..

This is the preferred jdk to work on.

java Plugins can be added using the "sudo apt-get install sun-java6-plugin " command


If we need to install ant, just enter "sudo apt-get install ant"

Type Y if prompted for Do u want to continue..


To Install tomcat6,

the command to be used is "sudo apt-get install tomcat6"


Cheers :D

Thursday, February 10, 2011

Load Testing Tool For GWT

Long time no see......
Wondering what I was doing so long??

Well, lot of changes, actually..
I have moved over to using Ubuntu from Windows, and currently I am working on web app development using GWT, Spring and Hibernate.
Post application development, it's now the season of Testing!
Currently, I am on the lookout of a Load Testing tool for GWT.
Though there are tools out there in the web, search for a Load testing tool that uses GWT that supports Linux is getting more difficult each day..
This is my current status!

Friends, In case you come across any Load testing tool, let me know.

!!! HELP TO THE NEEDED !!!