JavaEE开发中程序架构设计不仅会影响程序性能、复杂性,同时还影响到程序的可扩展性和可维护性,目前业界有规范的JavaEE架构设计被奉为经典,下面将按照是否分布式进行介绍。
非分布式架构:
1.Web应用搭配业务组件接口架构:
经典三层架构:用户接口层、业务逻辑层和持久化层。
优点:
(1).架构简单,是最常用最简单的Web应用架构,但是如果涉及到事务或者多线程问题时,需要编写比较复杂代码,不如直接使用EJB简单。
(2).程序运行速度快,这种架构很少遇到EJB容器的速度开销问题。
(3).不会遇到因EJB调用而破坏面向对象设计原则问题。
(4).测试简单,如果设计的得到,业务逻辑层不需要依赖Web容器就可以测试。
(5).扩展性比较好,若Web应用是无状态的且非分布式的,不需要依赖EJB容器提供的集群支持。若Web应用是分布式的且有状态的,则可以利用Web容器对状态替换的支持。
缺点:
(1).这种架构只支持Web应用的客户端,不支持standalone的java客户端。
(2).整个应用程序运行在同一个java虚拟机中,虽然提高了性能,但是无法自由将应用程序模块分配到不同的物理服务器上。
(3).这种架构无法使用EJB容器对事务的支持,必须在应用程序中编写事务创建和管理的相关代码(Spring等第三方框架可以提供类似javaEE容器的声明式事务)。
(4).这种架构无法使用EJB容器对并发