Thursday, May 29, 2014

Kill a Process running on a specific port in windows OS (i tested in windows 8.1)

1 . Find which process is running on the specific port with the below command

netstat -ano

2 . Then take the PID (which in my case is in the last column) , then run the following command

taskkill  /F /PID <<pid>>

once you run the above command and if the process killed successfully then you will see the below message

SUCCESS: The process with PID <<pid>> has been terminated.


* <<>pid>>  represents the pid which is using the specific port number.

Sunday, May 18, 2014

JAVA NIO , BUFFER , LIMIT and POSITION

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class FileNIO {

public static void main(String[] args) throws IOException {
try {
FileOutputStream fout = new FileOutputStream("nio.txt");

FileChannel fc = fout.getChannel();

ByteBuffer bb = ByteBuffer.allocate(10);

bb.clear();

for (int i = 0; i < 10; i++) {

System.out.println("space left in the buffer "+bb.limit());
System.out.println("next element where the data need to be put :"+bb.position());

bb.put((byte) 'A');

}

System.out.println("space left in the buffer "+bb.limit());
System.out.println("next element where the data need to be put :"+bb.position());


bb.flip();

fc.write(bb);

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}




will print the following output



space left in the buffer 10
next element where the data need to be put :0
space left in the buffer 10
next element where the data need to be put :1
space left in the buffer 10
next element where the data need to be put :2
space left in the buffer 10
next element where the data need to be put :3
space left in the buffer 10
next element where the data need to be put :4
space left in the buffer 10
next element where the data need to be put :5
space left in the buffer 10
next element where the data need to be put :6
space left in the buffer 10
next element where the data need to be put :7
space left in the buffer 10
next element where the data need to be put :8
space left in the buffer 10
next element where the data need to be put :9
space left in the buffer 10
next element where the data need to be put :10

Thursday, May 15, 2014

JSTL Cookie

To access the cookie using the jstl in jsp

{cookie.cookieName.value}  will return the value 

Wednesday, December 19, 2012

What is ACID , in simple words


A stands for Atomicity, Atom is considered to be smallest particle which can not be broken into further
pieces.database transaction has to be atomic means either all steps of transaction completes or none of
them.
C stands for Consistency, transaction must leave database in consistent state even if it succeed or
rollback.
I is for Isolation
Two database transactions happening at same time should not affect each other and has consistent
view of database. This is achieved by using isolation levels in database.
D stands for Durability
Data has to be persisted successfully in database once transaction completed successfully and it has to
be saved from power outage or other threats. This is achieved by saving data related to transaction in
more than one places along with database.

Monday, October 22, 2012

how to return from the method when a timeout has occured

usecase : when we have a method abc() , and caller of this method will wait for 10 min for the resposne from this method, once the time has expired , then caller won't wait for the method response and return from the method.

solution : this can implemented as follows


example :




import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class TimeOutTesting {

public static void main(String[] args){

ExecutorService executor = Executors.newSingleThreadExecutor();
Callable<Object> task = new Callable<Object>() {
  public Object call() {
     return gettheCOntext();
  }
};
Future<Object> future = executor.submit(task);
try {
  Object result = future.get(0, TimeUnit.MILLISECONDS);
 
  System.out.println("hi how are you");
  System.out.println(result.toString());
} catch (TimeoutException ex) {
  System.out.println("time out exception has occured");
}
catch(Exception e)
{System.out.println("Exception has occured");}
finally {
  future.cancel(false); // may or may not desire this
}

}

public static String gettheCOntext()
{
String ramesh="ramesh";
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ramesh;
}

}