J2EE application performance optimization

With the outbreak in the internet economy, the need for independent application development for the enterprises is starting to rise. A standardised architecture for database management is very much the need for J2EE enterprise application development. Java with its J2EE (Java 2 enterprise edition) has gained acceptance and became the standard for enterprise architecture.  J2EE helps enterprises adopt simple processes of developing applications and reduces programming and training expenses because the platform lets developers create standardized, reusable modules. Besides, the platform also facilitates multi-tier architecture to manage different programming aspects automatically.

The advent of the J2EE framework changed the way the enterprise application architecture was defined. It also paved a way for a surplus of service architectures like clusters of servers offering differentiated services, the client-server, the GUI-application layer-operational and layer-database concepts which have become standards today. As applications progress from development to production stage, performance becomes a significant life-cycle requirement. Applications not only need to meet severe performance requirements on deployment, but they should also be able to scale with everchanging usage patterns and increased demand. In this article, we’ll examine several ways that can help improve the performance of a J2EE application. We’ll also look at some of the Java code level optimizations as well as best coding practices. Lastly, we’ll look at JVM specific tuning tips and architectural changes to enhance the performance and make a Java business application a secure software.

Performance goals

Before we think about optimizing the performance of the application, we need to define and understand our non-functional requirements around areas like scalability, performance, availability. It is always a good idea to choose project goals before the development stage begins.  Choosing project goals in advance allows tradeoff decisions to be made easily during the development cycle. It should contain a general statement of the kind of performance required from the application. The possibilities for performance goal choices differ based on the type of application being built.  

Added optimization is to minimize the number of round trips made between tiers. It has been part of performance goals for Oracle database servers. Here are a few commonly used performance goals for scalable J2EE web applications:

Using these metrics can be measured via various load testing and application monitoring tools helps to identify key bottlenecks and adjust performance accordingly.

Follow a structured procedure for improving performance

It is interesting to make changes to the application that remarkably improve performance, however, not very much to make the wrong performance changes. It is easy to make changes that theoretically are supposed to enhance performance but never seem to make a difference. If you take one thing away from this article, it should be that a stepwise approach should be followed for improving performance. 

Step 1: Make sure the application functions correctly and resolve any memory leak issues. If you measure the performance of an application that has memory leaks, the results will be inconclusive, as the time to allocate additional memory will be included in it. Also, the application tends to run slower as more memory is leaked over time. 

Step 2:  Build a test environment that resembles your deployment environment. If the actual application will access the database server over a dial-up modem or high-speed network connection, do the same in your test environment as well. A good test environment will help assure that the performance characteristics you see are the same as your customer's.

Step 3: You need to simulate the clients using the application so that you can measure for your preferred performance goals. Some of the possible metrics to decide on are:

  1. Max response time under peak load.
  2. CPU utilization under peak load.
  3. How the application scales when extra users are added.

Step 4: Identify the precise execution code paths that need to be altered to improve performance for every user. You could use a profiler tool that measures the performance of the code in the application. When you execute the load test with a single user, measure the performance of the application. Next, identify the execution paths in the application that takes up the most time.  The notion here is to find the code that takes up the most time in the application and update it to be secure and fast.

Step 5: The next step is to recognise the key bottlenecks that need to be eliminated to enhance performance. Many of the JVM has a built-in "show me the state of the Java process" feature. This process shows you a screengrab of each Java thread's stack trace. The stack trace tells you what line of Java code is executing in each thread and the method that called it. 

Step 6: Execute the application under the client load test created in step 3 and measure your application performance to see if the expected performance goals have been satisfied. There are commercially available client load testing tools that can measure the performance of the application under different loads. If the application response time is slow, you should repeat step 4 to improve the execution path performance more. You can also try to profile the application while it is operating under the big client load, but the profiler may not always be capable of handling it, as it may run out of memory. If the application does not compute to a large number of users,  repeat step 5 to see if you dropped a bottleneck.

Identifying Bottlenecks

Once a particular area of the application improves, another one will become a bottleneck. Repeat the cyclic method of identifying the bottleneck, then resolving it, followed by identifying the next bottleneck until the desired performance goal has been fulfilled. You should have two kinds of tools for this process, stress tools that generate load for your application and monitoring tools that collect data for various performance indicators.

Load testing tools and Application Performance Management (APM) solutions are usually used to track and optimize the performance of J2EE applications. Running load tests encompassing different application scenarios and simultaneously monitoring CPU, IO and Heap usage with the help of APM tools are key to identifying bottlenecks. Gatling is one the known tools for load testing which provides exceptional support of the HTTP protocol that makes it a great choice for load testing any HTTP server.  A complete monitoring tool like Gatling covers the front part of unlocking the performance potential of your Java app. The other part is being able to replicate real-world usage and load in your system.

Performance monitors

Using a monitoring tool, you assemble data for various system performance indicators for all the suitable nodes in your network topology. Many stress tools come with monitoring tools, for example, Windows OS also has a built-in performance monitor fit for many purposes. The Windows performance monitor can be run from the Administrative Tools menu in the Control Panel menu, or by simply typing "perfmon" in the Run window ( from the Start menu). You can display the performance counters data in real-time, but logging this data into a file is a better option so you can view it later. To do that, proceed to the Counter Logs selection in the left-hand side of the Performance window, right-click and select New Log Settings.

Java Performance Tuning: Conclusion

Java developers believe that performance optimization is an intricate topic that requires a lot of experience and knowledge. While that’s not entirely wrong, optimizing a J2EE application to get the best performance is possible through followable steps, even if you’re not a performance tuning expert. Therefore performance tuning is the best option after Custom J2EE development of any kind of enterprise-level scalable and high- performance web application.

Evon technologies has decade-long and extensive experience in J2EE for enterprise applications integration, Java front-end and backend frameworks, along with a design-centric approach to help you meet your business and technology goals. We offer a broad domain of enterprise application services: from ERP, B2B and B2C Web Portals to Business Intelligence & Analytics, and CRM. Our deep experience in J2EE based web and app development has led us through building, optimizing and performance tuning scalable J2EE web apps, Enterprise Information Portals, and Enterprise integration. Contact us to hire J2EE developers or email us at This email address is being protected from spambots. You need JavaScript enabled to view it. to know about how we are keeping up with the shift in the industry.