There are multiple approaches to display double or float data with 2 decimal places in Java. The post presents a way using DecimalFormat. Continue reading
Category Archives: Java
Difference between String, StringBuffer and StringBuilder
In Java, String, StringBuffer and StringBuilder classes are widely used. In many scenarios, any of them can be used. However, there are minor differences between these classes. Continue reading
How to Optimize Tomcat Performance
The default Tomcat configuration looks powerful and hassle-free to the 1st time users. However, it is not customized for the real work where high server load can be expected. Therefore, it is important to optimize Tomcat performance by setting customization and system tuning.
The post will describe how to optimize Tomcat performance. Continue reading
JBoss 8009 Port in Use BindException Fix
You may want multiple application servers to be deployed into the same server, for example one Tomcat 6/7, one JBoss Application Server 6.x, or three JBoss Application Servers. Assuming Tomcat 6.x is running, when you start JBoss AS 6.1, you might see JBoss 8009 Port in Use BindException in the jboss boot log: Continue reading
When and How to Use ThreadLocal in Java
What is ThreadLocal?
In Java, ThreadLocal has been used since JDK 1.2. In multi-threaded programming, there are multiple ways to achieve thread safety via synchronization / locks. ThreadLocal is a different way to achieve thread-safety by providing explicitly a copy of Object to each thread. Since the Object is not shared, there is no requirement of Synchronization. Therefore, it will help the application performance & system scalability improvement. Continue reading
File Change Notification with Watch Service API
Since Java 7, the java.nio.file package adds a feature: file change notification with Watch Service API – java.nio.file.WatchService
. Watch Service API allows us to register directories with the watch service, and monitor the directories and files for any changes including creation, deletion, modification etc. The post will briefly introduce the usage of Watch Service API. Continue reading
Daemon Thread in Java
Daemon thread is a service provider thread with low priority. Normally, it is used to provide service like background supporting tasks (garbage collection etc.). Its life depends on normal non-daemon threads. If all non-daemon threads are not running, the daemon thread will terminate. Continue reading
Java Thread States and Life Cycle
Thread is a lightweight sub-process. The state diagram below shows Java thread state change and life cycle. Continue reading
Create and Start a Thread in Java
Threads are lightweight sub-processes which share the same address space and data, and can execute different tasks concurrently. Compared to processes, context switching between threads is less expensive. In Java environment, a Java thread is an instance of Thread class or its subclasses. Continue reading
Hibernate Session
The main function of a Hibernate session is to open a database connection, and offer read and update operations for instances. Each instance object associated with the session will keep alive until the session is closed or the object is deleted. Continue reading