Posts Tagged Java
limitToList attribute prevents flashing
If you have some elements (or even the whole page) that flash/twinkleย using RichFaces, it probably means that these elements are AJAX-rendering. The question is by whom and how to fix it?
A lot of tags in RichFaces can AJAX-render elements such as:
<a4j:form> <a4j:jsFunction name="updateName" reRender="showname"> <a4j:actionparam name="param1" assignTo="#{userBean.name}" /> </a4j:jsFunction> </a4j:form>
On the above example, the JavaScript function updateName
will AJAX-render the element which has the ID showname
.
In some cases, you would have some elements that would AJAX-render without asking them to do so!
I still didn’t figure it out why. ๐ (if anybody has an idea, please don’t hesitate to tell me!)
But, I found a way to prevent this!
You simply can add the following attribute to your tag:
limitToList="true"
You even can add it to the tags that don’t have a reRender
attribute.
For example:
<a4j:form> <a4j:poll id="poll" interval="1000" limitToList="true" /> </a4j:form>
Deploy your app to the root context
This is an easy trick which I am sure most of you already know.
Let’s take a Java application called MyAddressBook. Its generated war file could be called myaddressbook.war
.
By default, when you deploy this web application to Tomcat, the URL to access it will be http://localhost:8080/myaddressbook/. And if you point a domain name such as ‘addressbook.com’ to this server, the URL would be http://addressbook.com/myaddressbook/.
I don’t know for you but I don’t like to systematically have the subfolder ‘myaddressbook’ after my domain. But maybe I am too picky! ๐
The idea is to deploy our application in the Tomcat root context.
You have two ways of doing this:
- Define a
ROOT.xml
file in yourconf/Catalina/localhost
folder, or; - Rename your war file to
ROOT.war
.
Note that the case is important, it has to be ROOT in UPPERCASE! ๐
Once this is done, you will be able to call your application via the URL http://localhost:8080/
or http://addressbook.com/. Way better! ๐
How to monitor your Java application
It is very good to have your application and your database running on a Linux or Windows server, but who will tell you if your website is down? Who said “the users”? ๐ฏ No, you won’t look very professional if you wait for a user complaint.
What you need to do is to monitor your server. But which tools to use? There are so many on the market… ๐
I tested a few of them (Hyperic, Nagios, Zenoss, Cacti, Monitis) but the one I choose is Zabbix. What I like with Zabbix is its price (free ๐ ) and the fact that it is easy to configure and very flexible. Indeed, you can monitor anything you want on the machine (CPU, network, disk space, services, etc)! ๐
However, if you also want to monitor your Tomcat application server or even Hibernate Java library, you need some more work.
To monitor Tomcat, you first need to enable JMX Remote. To do so, you can have a look at the official documentation or simply add the following parameters to your Tomcat startup script:
export CATALINA_OPTS='-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false'
Then, I will recommend you to deploy Zapcat JMX Zabbix Bridge in your Tomcat web server. This tool has been developed to simplify the communication between the JMX management API inside Java applications and the Zabbix monitoring tool.
To read the installation instructions for Tomcat, please click on the following link:
http://www.kjkoster.org/zapcat/Tomcat_How_To.html
Finally, if you are using Hibernate in your Java application and would like to monitor it, you have to instantiate and configure a Hibernate MBean (org.jboss.hibernate.jmx.Hibernate
) that will be responsible for constructing a Hibernate SessionFactory
and exposing it to your application through JNDI.
Here are the lines you need to add to your context XML file:
<bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> <property name="server" ref="mbeanServerFactory"/> <property name="beans"> <map> <entry key="org.hibernate:type=statistics" value-ref="hibernateMBean"/> </map> </property> </bean> <bean id="mbeanServerFactory" class="org.springframework.jmx.support.MBeanServerFactoryBean"> <property name="locateExistingServerIfPossible" value="true"/> </bean> <bean id="hibernateMBean" class="org.hibernate.jmx.StatisticsService"> <property name="sessionFactory" ref="sessionFactory"/> <property name="statisticsEnabled" value="true"/> </bean>