public class Test {
public static void main(String args[]){
Test test = new Test();
TestShutdownHook testshutdownHook = new TestShutdownHook(test);
Runtime.getRuntime().addShutdownHook(testshutdownHook);
test.startTest();
}
private void startTest() {
int counter = 0;
while(true){
if(counter == 100){
System.exit(0);
}
System.out.println("Running..");
counter++;
}
}
public void beforeShutdownDothis() {
System.out.println("Doing somethig before shutdown");
}
}
package com.my;
public class TestShutdownHook extends Thread {
private Test test;
public TestShutdownHook(Test test){
this.test = test;
}
public void run(){
test.beforeShutdownDothis();
}
}
Wednesday, 8 July 2009
Writing a JVM shutdown hook
Following is the class which exits on some condition. So before exit, if we need to carry out some task, register a shutdown hook(TestShutdownHook.java) with JVM
Useful tips for Spring beans initialization
Referring to Constants in the bean initilization
Using the static factory for creating NON singleton beans. Even though, parameters are in 'constructor-arg' element, those are treated as normal parameters to method call.
Write the following code in the class which implements BeanFactoryAware , InitializingBean interfaces.
Using the static factory for creating NON singleton beans. Even though, parameters are in 'constructor-arg' element, those are treated as normal parameters to method call.
0
test
0
Write the following code in the class which implements BeanFactoryAware , InitializingBean interfaces.
String testFileSystemNames[] = {"/","/usr","/exports"};
Object args[] = new Object[3];
ListfileSystemObjects = new ArrayList ();
for(int i=0; i< testFileSystemNames.length; i++ ){
args[0]=i+1;
args[1]=testFileSystemNames[i];
args[2]=i;
FileSystem fileSystem = (FileSystem)beanFactory.getBean("fileSystem", args);
fileSystemObjects.add(fileSystem);
}
Monday, 1 June 2009
Quick Tip for using SimpleJdbcTemplate
When using SimpleJdbcTemplte.queryForMap method, remember that the results returned as Map has keys in all capital letters. e.g
Map results = template.queryForMap("select id, balance from Account where id=?", account.getId());
In above case, to retrieve the value of id and balance use results.get("ID") and results.get("BALANCE") instead of results.get("id") and results.get("balance");
:)
Map
In above case, to retrieve the value of id and balance use results.get("ID") and results.get("BALANCE") instead of results.get("id") and results.get("balance");
:)
Monday, 30 March 2009
Sunday, 22 March 2009
RIA - Flex with BlazeDS and Spring Integration
1. Create a new Flex Project with following selections :
Project name: HelloWorld
Application server type: J2EE
Select 'Use remote object access service with LiveCycle data Service'
Select 'Create combined Java/Flex project using WTP'
On Next screen -> Select the appropriate Target runtime.
Flex WAR File - point to blazeds.war file.
On Next screen -> select serverport as configured on your system.
Click, Finish.
2. Under src folder, create a new java class 'HelloWorld' with method signature as follows :
public String sayHello(String name)
3. Declare the spring dispatcher servlet in web.xml file as shown in following fig. All the spring beans will be defined in file 'web-application-config.xml'.

4. Create spring configuration file (helloworldservlet.xml) under WEB-INF folder. Do not declare any spring beans in this file.
5. Create web-application-config.xml under WEB-INF/config directory. Declare the HelloWorld bean and expose it as mentioned below.

6. Add the necessary libraries in lib folder in WEB-INF .
7. Add the default channel in service-config.xml file. This is very important. Enable the channels by providing server name, port name and content root.
8. Add the following code to HelloWorld.mxml file between mx:Application elements.

9. Start the server. Ensure that application is deployed properly.
10. Run the HelloWorld.html file under bin-debug by right click -> Run as -> Run On server by selecting proper server.
11. Enter your name and click the Submit button. Application should respond with Greetings to you !

Hope this helps you !
Project name: HelloWorld
Application server type: J2EE
Select 'Use remote object access service with LiveCycle data Service'
Select 'Create combined Java/Flex project using WTP'
On Next screen -> Select the appropriate Target runtime.
Flex WAR File - point to blazeds.war file.
On Next screen -> select serverport as configured on your system.
Click, Finish.
2. Under src folder, create a new java class 'HelloWorld' with method signature as follows :
public String sayHello(String name)
3. Declare the spring dispatcher servlet in web.xml file as shown in following fig. All the spring beans will be defined in file 'web-application-config.xml'.
4. Create spring configuration file (helloworldservlet.xml) under WEB-INF folder. Do not declare any spring beans in this file.
5. Create web-application-config.xml under WEB-INF/config directory. Declare the HelloWorld bean and expose it as mentioned below.

6. Add the necessary libraries in lib folder in WEB-INF .
7. Add the default channel in service-config.xml file. This is very important. Enable the channels by providing server name, port name and content root.
8. Add the following code to HelloWorld.mxml file between mx:Application elements.

9. Start the server. Ensure that application is deployed properly.
10. Run the HelloWorld.html file under bin-debug by right click -> Run as -> Run On server by selecting proper server.
11. Enter your name and click the Submit button. Application should respond with Greetings to you !

Hope this helps you !
Thursday, 27 March 2008
Subscribe to:
Posts (Atom)
