Friday, 28 August 2009

Optimize Firefox Speed

  You can use pipelinning to speed up page load.Which allows Firefox to load multiple things at once.

    * Type “about:config” into the address bar and hit return.
    * Type “network.http.*pipe” in the filter field, and change the following settings.       
    (Double-click on them to change them):
    * Set “network.http.pipelining” to “true
    * Set “network.http.proxy.pipelining” to “true
    * Set “network.http.pipelining.maxrequests” to "8".




Helpful Links
http://egonitron.com/2007/05/25/the-truth-about-the-firefox-pipelining-trick/

Wednesday, 26 August 2009

Packge once. Deploy everywhere

I was looking for a software to bundle my application as one installer. So it can deploy it any where. I found open source product IzPack. It requires only a Java virtual machine to deploy.

IzPack : http://izpack.org/

There are some commercial product available, Following products are used to create windows installer (msi) package.

InstallShield
Advanced Installer

Some more free tools ..

Windows Installer XML (WiX)
InstEd
NSIS

Saturday, 22 August 2009

Eclipse Plug-In - Easy Explorer

Easy Explorer is a very useful plug in, Which helps you to browse resources with the native Operating system explorer. In the Eclipse, select a file, right-mouse click, and select the 'Easy Explore...'

I am using Galileo & easy-explore-1.0.4.

Image Magnification Testing :(






Plug-In details links

Easy Explorer Home
Download Plug-in

Tuesday, 2 June 2009

Daemon Thread in Java


  • Any thread created by main thread is by default user thread. Because when a new thread is created it inherits the daemon status of its parent. (Check output result)
  • Need to explicitly set daemon (setDaemon(true)) but this can only be called before starting thread otherwise it will throw IllegalThreadStateException if the related thread already started.  (Check output result) 
  • Normal thread and daemon threads differ in what happens when they exit. When the JVM halts any remaining daemon threads are abandoned: Finally blocks are not executed. Stacks are not unwound and JVM just exits. (Check output result)
  •  Main different is that as soon as all user thread finish execution java program or JVM terminates itself, JVM doesn't wait for daemon thread to finish there execution. As soon as last non daemon thread finished JVM terminates no matter how many Daemon thread exists or running inside JVM. (Check output result)


Sample Code

public class DaemonTest {

    public static void main(String[] args) {
        System.out.println("Entering main Method");
        WorkerThread wt = new WorkerThread();

        // When false, (i.e. when it's a user thread),
        // the Worker thread continues to run. finally block will run
        // When true, (i.e. when it's a daemon thread),
        // the Worker thread terminates when the main thread terminates. finally block doesn't run
        /** Set daemon flag */
        wt.setDaemon(true);
        wt.start();
        try {
            Thread.sleep(7500);
            System.out.println("Main Thread wake up");
        } catch (InterruptedException e) {
        }
        System.out.println("Main Thread ending");
    }

}

class WorkerThread extends Thread {

    public void run() {
        System.out.println("Entering WorkerThread run method IsDaemon:" + Thread.currentThread().isDaemon());
        try {
            System.out.println("In run Method: currentThread() is" + Thread.currentThread());
            int count = 0;
            while (count < 10) {
                System.out.println("Hello from Worker " + count++);
                try {
                    sleep(2000);
                } catch (InterruptedException e) {
                }
                System.out.println("In run method: woke up again");
            }
        } finally {
            System.out.println("NOTE : Leaving Worker run Method running finally block");
        }
    }
}


Output: User thread / Non-Daemon thread
Entering main Method
Entering WorkerThread run method IsDaemon:false
In run Method: currentThread() isThread[Thread-0,5,main]
Hello from Worker 0
In run method: woke up again
Hello from Worker 1
In run method: woke up again
Hello from Worker 2
In run method: woke up again
Hello from Worker 3
Main Thread wake up
Main Thread ending
In run method: woke up again
Hello from Worker 4
In run method: woke up again
Hello from Worker 5
In run method: woke up again
Hello from Worker 6
In run method: woke up again
Hello from Worker 7
In run method: woke up again
Hello from Worker 8
In run method: woke up again
Hello from Worker 9
In run method: woke up again
NOTE : Leaving Worker run Method running finally block

Process finished with exit code 0



Output: Daemon thread
Entering main Method
Entering WorkerThread run method IsDaemon:true
In run Method: currentThread() isThread[Thread-0,5,main]
Hello from Worker 0
In run method: woke up again
Hello from Worker 1
In run method: woke up again
Hello from Worker 2
In run method: woke up again
Hello from Worker 3
Main Thread wake up
Main Thread ending

Process finished with exit code 0



Output: Setting daemon flag after starting thread
Entering main Method
Exception in thread "main" java.lang.IllegalThreadStateException
 at java.lang.Thread.setDaemon(Thread.java:1275)
 at com.java.concurrency.c1.DaemonTest.main(DaemonTest.java:16)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Entering WorkerThread run method IsDaemon:false
In run Method: currentThread() isThread[Thread-0,5,main]
Hello from Worker 0
In run method: woke up again
Hello from Worker 1
In run method: woke up again
Hello from Worker 2
In run method: woke up again
Hello from Worker 3
In run method: woke up again
Hello from Worker 4
In run method: woke up again
Hello from Worker 5
In run method: woke up again
Hello from Worker 6
In run method: woke up again
Hello from Worker 7
In run method: woke up again
Hello from Worker 8
In run method: woke up again
Hello from Worker 9
In run method: woke up again
NOTE : Leaving Worker run Method running finally block

Process finished with exit code 1


NOTES:
Daemon thread which runs in background and mostly created by JVM for performing background tasks such as

  • Garbage collection
  • Performing asynchronous I/O task. ????
  • Listening for incoming connections ????
  • Collecting statistics and performing the status monitoring tasks
    • Sending and receiving network heartbeats , supplying the service monitoring tools
  • House keeping jobs


Monday, 16 March 2009

Things to note when desinging a module

Some points to consider when we designing or implementing application. These points will helpful to diagnose or fix issues in production environment. Will update whenever my code bite back :)
  1. Externalizing configuration values in database or .properties or XML files.
  2. Testing the application with the volume of data in production.
  3. Set proper timeout functions 
  4. Set limit to retry functions to connect to third party or external services 
  5. Browser compatibility checking
  6. Proper database design Column to indicate created, updated time and user details, Active or delete flag
  7. Security