Sunday, September 22, 2013
Monday, January 21, 2013
how to add a column to a table after a specific column
alter TABLE student add column age int(4) after name
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;
}
}
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;
}
}
Saturday, October 20, 2012
Monday, October 15, 2012
how to see the tree structure of folders in unix
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
Subscribe to:
Posts (Atom)