Method with @Transactional commits the transaction when it returns. If you want to combine multiple transactional method in one transaction, propagation policy is the solution. Solution A To make a parent method with @Transactional To delete @Transactional at sub methods to combine the transaction Solution B To make a parent method with @Transactional (default propagation … Continue reading Combining multiple transactional method in one transaction
Category: Java
Spring Transaction with @Transactional explained
The most easy way to Spring Transaction is to use @Transactional. The following is basic step to use it. Required spring component spring-context.jar, spring-tx.jar, spring-jdbc.jar and additional dependencies Spring context <tx:annotation-driven> must be declared to enable @Transactional TransactionManager must be declared. If the id is not "transactionManager", it must be set with <tx:annotation-driven>'s transaction-manager attribute … Continue reading Spring Transaction with @Transactional explained
Sending data from controller to view
Most dynamic web pages are composed of template and data. In Spring MVC, data is sent usually from controller to view. How to send data (from controller's point) Usually data is created in controller. The following is some ways to send data. (Not exhaustive explanation. More on RequestMapping handler method) To declare Model as parameter … Continue reading Sending data from controller to view
Java heap dump from command line
jmap -J-d64 -dump:format=b,file=/path/to/dump/file java_pid * -J-d64 : in case of 64bit jdk
About Spring ViewResolver
ViewResolver is very important component of Spring MVC. Without proper understanding, it is difficult to analyze MVC components, especially when taking over other's source code. The following explanations is based on Spring Framework 4.3.18. What is ViewResolver? (org.springframework.web.servlet.ViewResolver) ViewResolver is the translator which converts view name into View object View is the component which renders … Continue reading About Spring ViewResolver
Oracle JDBC slow connection on some virtual server
This issue is found on Oracle JDBC driver 11.2.x. Environment : Linux virtual server, Oracle JDBC driver 11.2.x Issue : Oracle connection takes long time or occurs timeout error Cause : Oracle JDBC driver, when it connect to database server, calls java.security.SecureRandom class. SecureRandom uses /dev/random on Linux or Unix server. /dev/random pseudo device uses … Continue reading Oracle JDBC slow connection on some virtual server
Java runtime parameters to enable JMX
To enable JMX for some java process, the following option is required. -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9099 -Dcom.sun.management.jmxremote.rmi.port=9199 The important two ports are com.sun.management.jmxremote.port and com.sun.management.jmxremote.rmi.port. If JMX client is connecting through firewall, the two ports must be opened.
The inner working of DispatcherServlet
The main program of Spring MVC is DispatcherServlet. Most Spring MVC webapp's web.xml is as follows. <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> … Continue reading The inner working of DispatcherServlet
8 ways to declare Spring beans
Beginning Spring programming is simple, but it's difficult to take over someone's source code. In my opinion, it stems from different ways to declare Spring beans. I summarized 8 ways to declare Spring beans. 1. Xml based bean configuration The bean itself is just a pojo class. Inside bean configuration xml, the following tag declare … Continue reading 8 ways to declare Spring beans
Tomcat sticky session
Common web architecture is Web - WAS - (DB). For example, Apache as Web Server and Tomcat as WAS. In this case, mod_jk is is used to connect from Apache to Tomcat. The following is Web to WAS load balancing architecture. With this architecture, multiple http request is sent to Tomcat#1 and Tomcat#2 in round … Continue reading Tomcat sticky session