Principles for developing J2EE applications

Source: Internet
Author: User

J2EE is a complete set of standardized integrated platform for developing enterprise-level applications with mission-critical. It has many specifications and wide content, which brings a lot of "trouble" to the Development of J2EE applications ". For example, to implement Content-based RDBMS storage, we may use JDBC, entity beans, JDO, O/R Mapping tools (toplink, Hibernate), XML-DBMS, jaxb, and other methods (some of which are not included in the J2EE specification ). Therefore, to realize the coupling between layers (at least three layers of J2EE, including the presentation layer, control layer, and commercial logic layer) and between layers, the J2EE system architect has many issues to consider. In addition, the rapid development of J2EE brings some difficulties to the architecture and development of industrial-strength J2EE applications.

At the same time, software development technology has never been "Silver Bullet", so J2EE technology is not omnipotent. However, if we properly apply the J2EE technology based on specific business needs, the results can be imagined. This article tries to start with my previous project experience to discuss several principles that should be followed when developing J2EE applications, hoping to serve as a reference. This article takes J2EE application development under JBoss 3.2.1 as an example to describe.

  1. Select a reasonable architecture based on business needs

It is not enough to discuss the advantages of technology independently from business needs. Various technologies have specific backgrounds, many of which are driven by industrial needs. Generally, enterprise information systems (EIS) require stability, security, reliability, efficiency, and easy maintenance. At the same time, each enterprise's information system has its own unique requirements, and sometimes it is necessary to consider integration with the original legacy system, therefore, understanding the specific business needs of enterprise information systems is critical to the entire system architecture.

  For example, if most of the data used in the J2EE application system to be developed comes from external data sources;The data may be imported directly from the external data source to the database of the J2EE system to be developed through JDBC. In this case, if you only use JDBC to operate the database during the development process, it is obviously appropriate for scenarios with low strength (fewer concurrent users and less data streams; however, if the database layer is frequently used due to a large number of concurrent access users and a large amount of data streams, it seems a little powerless. Therefore, for this requirement, we can consider using entity beans with caches. For example, there are multiple cache policies for entity beans in JBoss 3.2.1. You can consider using these policies, that is, "Standard CMP 2.x entitybean ", the "D" type commit-option method is used to ensure the synchronization of entity beans content and data sources, and greatly improve the system performance (compared with the direct use of JDBC ). You can set some entity beans to read-only to improve performance. Of course, other O/R mapping technologies, such as toplink, can also be used here.

  For another example, consider the following situation: if the data used by the enterprise information system to be developed is generated and operated by the system itself,We recommend that you use the CMP Entity beans technology. Entity beans has a bad impression on everyone. This may be related to the bad image that EJB 1.1 has left for everyone. However, EJB 2.0 (or 2.1) has been greatly improved, including local interfaces, CMR, read-only, and session fa? The Ade mode Injects Vitality into entity beans. Of course, the advantages of entity beans can be reflected only when many concurrent users and large data traffic are involved. One of the key points is to pay attention to the performance tuning of entity beans technology. Each application server has its own performance tuning solution. For JBoss 3.2.1, the configuration file standardjboss. XML provides an entry for entity beans technical optimization. For example, the rational use of bean lock policies is very important for tuning entity beans. In this way, we can focus more on the commercial logic of the system, not just the underlying database (EJB tuning is in the EJB iner, so we are at the high-end of J2EE performance, not the bottom, that is, the database layer. At the same time, the database-layer optimization greatly compromises the database portability of the J2EE system .).

In short, we need to give specific technical architecture solutions based on the specific needs and conditions of each system, rather than discussing the quality of the technology itself alone.

  2. Reasonable Selection of Framework

The design pattern plays an important role in the J2EE application system. Therefore, there is a question for everyone: whether to implement a specific design pattern or use third-party framework. If your company is not large, or you do not want to invest a lot of energy in the basic J2EE application framework, it would be wise to choose a more mature and stable technical framework that is compatible with the existing J2EE specification.

Generally, the framework itself, or the J2EE platform itself, implements and optimizes specific design patterns and rules,For example, the Service proxy and service locator (including the service Locators of Web Tier and EJB Tier respectively play a role in unified management of limited resources and cache-related resources, facilitating system migration) front Controller, Dao, etc. The existing J2EE framework is rich. For example:

Struts: it is wise to use the framework of model 2 in the present and future (along with the maturity of JSF specifications and technologies. Currently, Struts has been developed to version 1.1. Its internal MVC main line, no restrictions on backend data operations, and the excellent related projects of the Apache Jakarta project team are the best products for developing J2EE applications. At the same time, for the next-generation J2EE platform technology JSF with. NET web forms features, Struts itself can take into account the compatibility and integration with JSF. For example, the presentation layer is presented through JSP, the servlet presentation control layer, and the EJB presentation data storage layer. Each layer can communicate with each other through value objects and HTTP-related objects to achieve perfect application of J2EE-related technologies.

Log4j: I think log4j is a boon to readers who are used to "system. Out. println. Although Java 2 Standard Edition has a java. util. Logging package to ensure log output, the simplicity, efficiency, and flexibility of log4j have become the choice of many projects. To some extent, logs can test the stability and correctness of the system. Therefore, you can use configurable log4j (currently, log4j has been taken into account with Java. util. logging package compatibility. For example, JBoss 3.2.1 uses log4j to manage logs.

Realmethods: Some readers may not know this killer yet. Well, here is a brief introduction. Realmethods is a framework for developing J2EE applications. It is different from struts (mainly in Model 2 and J2EE application front-end). realmethods provides detailed and efficient support for all aspects of J2EE applications. At the same time, realmethods was previously a commercial software and has now become an open source product. Therefore, you can refer to all its source code.

Bc4j: A commercial component launched by Oracle for Java. Its content and external features and advantages are self-evident.

Of course, there are many similar frameworks. As a team developing J2EE applications, we need to filter various frameworks and select a framework suitable for the project requirements, teams, and company development directions.

Generally, too many frameworks are not suitable for the target products to be developed. First, various J2EE technologies have developed rapidly, and too many frameworks make subsequent upgrades and maintenance of the system unfavorable. Second, we can learn from the good aspects, such as studying the corresponding design modes implemented by realmethods, and transform her to suit our project needs. Third, the framework itself will change. If too many options are selected, it will increase the burden on the development team, which is not conducive to project management. You can use the existing mature framework to improve your development efficiency and level.

  3. Selection of development mode

Developing J2EE applications requires target developers to master various technologies. However, this is not the case. As a team, everyone has their own different skill advantages, interests, and insights. At the same time, J2EE itself needs to reflect the social division of labor. Generally, our development team does not have the various development roles required by specification. There are usually three types of reality (or two types): artist, JSP programmer, and EJB programmer. In the face of such division of labor, the team should pay more attention to communication, communication, and code consistency.

In general, the team should try to use version control tools to manage code and try to have a complete running version every day. After a while, the team will adapt to this development model. Version control tools must be used to facilitate code management, control, and backup. This involves many layers. For example, the selection of development tools should take into account the use of version control tools and the rational use of modeling tools to facilitate effective communication and communication between teams.

Based on the existing development model, I personally think these three solutions are good. First, use together as the modeling tool, use JBuilder as the IDE tool, use VSS (or CVS) as the version control tool, and use JBoss as the server for developing J2EE applications. Second, use the full set of WebSphere Studio Tools. Third, use eclipse (or jcreator), ant, and xdoclets as development tools.

Of course, manual compilation, compilation, packaging, deployment, and testing of J2EE applications allow developers to understand the details of each development stage. However, I believe that it is wise for developers to choose powerful modeling and development tools as long as they are concerned about specific details. Development tools cannot improve the development skills of developers, but they can guide developers in the correct development direction. For example, the EJB genie provided by jbuidler 9 Enterprise has "STRUTS + EJB + session fa? Ade + value object "and other functions present the J2EE architecture that is widely used in the industry.

  4. Focus on testing at various stages

Testing is often overlooked by many project managers, who are unwilling to spend time and money, because it will increase the cost of the project. However, they ignore that the quality of project completion often has a great relationship with the cost of the project. For example, if the software quality is poor and has not gone through the test phase, the cost of subsequent deployment and operation will far exceed the cost of the early stage.

Testing is performed in stages. Unit tests, such as JUnit, are used to ensure proper functions. Integration testing to ensure that the system has no memory leakage and other content. Among them, optimizeite suite enterprise is very helpful for completing profiler, code coverage, thread debugger and other content. I remember that the content of a swing desktop application I wrote was leaked, but I did not solve the problem in many ways. Later, the answer was obtained using profiler. Therefore, currently we use optimizeite suite enterprise as a testing tool to develop applications. In particular, it is helpful to check the system memory leakage and performance during integration testing.

Tests are classified. Stress testing and performance testing. Currently, there is no good testing tool for tests that support J2EE applications. However, in general, the use of rational robot can also achieve good results.

Of course, there are many factors that can be used to successfully develop J2EE applications. For example, the successful application of entity beans is largely related to the design of the underlying database (if the design of the table structure is unreasonable, the performance of entity beans will be greatly reduced ); how to maximize mining and improve the J2EE skills of each team member. And so on.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.