TongWeb生产环境配置规范之三:优化TongWeb启动速度

除硬件资源本身的性能外,通过优化TongWeb相关参数,也可以提高TongWeb和应用的启动速度。主要参数如下:

1. 全局配置->轻量模式

说明:以轻量模式运行 TongWeb,此模式会在原版本的基础上关闭 EJB、JCA 等服务,若应用基于 Tomcat 或其它 Servlet 容器开发,则通常可以获得更好的兼容性。

当应用为web应用时,建议开启该配置。

2. 全局配置->并行部署应用

说明:以并行的方式进行应用部署,可尝试提高多应用部署的效率,但应用部署期间的日志打印会出现交叉。注:最大并行数受限于"全局配置"配置的"任务并行度"。

通常建议一个应用部署在一个TongWeb实例下,若存在多个应用部署在同一个TongWeb实例的情况时,为提高TongWeb启动速度可以开启。注意:

(1)若多个应用之间有依赖关系,则禁止开启该项,采用默认的串行启动顺序 ,并通过配置应用的**"启动优先级"**来指定应用的启动先后顺序。

(2) 若多个应用之间无依赖关系,则可以开启该项,应用并行启动, "启动优先级"配置失效。

3. **全局配置->**跳过扫描 jar 文件

说明:当 jar 的名称符合此模式时,则不再从该 jar 中扫描 TLD、web fragments 等信息。该模式可包含两个特殊字 符:"*"表示 0 个或多个字符,"?" 表示一个且只有一个字 符。注:配置多个以英文逗号分隔,如 tongweb*.jar,common*.jar。

当应用jar包过多,多余的扫描会影响应用的启动速度,并有可能引起某些java异常,如下两个类互相继承导致扫描时死循环。

bash 复制代码
2026-10-10 17:11:13 [WARN] - Unable to complete the scan for annotations for web application [server] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [org.jaxen.util.AncestorOrSelfAxisIterator->org.jaxen.util.AncestorAxisIterator->org.jaxen.util.AncestorOrSelfAxisIterator] java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [server] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [org.jaxen.util.AncestorOrSelfAxisIterator->org.jaxen.util.AncestorAxisIterator->org.jaxen.util.AncestorOrSelfAxisIterator]
at com.tongweb.server.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2117)
at com.tongweb.server.startup.OpenEJBContextConfig.checkHandlesTypes(OpenEJBContextConfig.java:519)
at com.tongweb.server.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2056)
at com.tongweb.server.startup.OpenEJBContextConfig.processAnnotationsStream(OpenEJBContextConfig.java:513)

将应用中不需要扫描的jar配置上,可以加快应用启动速度和避免异常。TongWeb默认已经将如下jar进行了过滤,无需再加。

bash 复制代码
# TongWeb默认过滤jar的名称
tongweb-*.jar,jakarta*.jar,ant-junit*.jar,ant-launcher.jar,ant.jar,asm-*.jar,aspectj*.jar,cglib-*.jar,cobertura-*.jar,commons-beanutils*.jar,commons-codec*.jar,commons-collections*.jar,commons-daemon.jar,commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,commons-math*.jar,commons-pool*.jar,dom4j-*.jar,easymock-*.jar,ecj-*.jar,geronimo-spec-jaxrpc*.jar,h2*.jar,hamcrest-*.jar,hibernate*.jar,httpclient*.jar,icu4j-*.jar,jasper-el.jar,jasper.jar,jaxb-*.jar,jaxen-*.jar,jdom-*.jar,jmx-tools.jar,jmx.jar,jstl.jar,jta*.jar,junit-*.jar,junit.jar,mail*.jar,objenesis-*.jar,oraclepki.jar,oro-*.jar,slf4j*.jar,taglibs-standard-spec-*.jar,tagsoup-*.jar,tools.jar,wsdl4j*.jar,xercesImpl.jar,xmlParserAPIs-*.jar,xmlParserAPIs.jar,xom-*.jar,fscontext.jar,imq*.jar,Hulk*.jar,derby*.jar

4. 应用->JSP 预编译

JSP 预编译通过异步方式进行编译,不会占用启动时间,且能提高第一次JSP访问时间。

5. 应用->资源加载策略

说明:设置加载应用的类库等资源所使用的索引策略。SIMPLE :在应用启动时,为资源文件创建索引。BLOOM:使用 布隆过滤器来优化索引。PURGED:使用布隆过滤器来加 速归档文件的查找,并在运行时可以进行清除操作。

**默认SIMPLE :**精确匹配,jar 少的时候性能好;依赖大量 jar 包的项目扫描慢。

BLOOM: 布隆过滤器 Bloom Filter,jar 包数量很多时,显著加速查找、缩短启动时间,但可能存在极小概率加载异常。

6. 应用->开启资源缓存

说明:缓存应用的资源文件,以提高应用服务的响应效率。注 :"应用热加载"与"资源缓存"同时开启时,文件删除后会出现文件找不到异常,请合理开启两个选项!

最大缓存大小,可缓存的单文件大小上限, 缓存时长"报大小不够。 日志报错:

bash 复制代码
[WARN] - Unable to add the resource at [/WEB-INF/classes/org/oasis_open/docs/wsrf/rp_2/jaxb.properties] to the cache for web application [cxf] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache 
[WARN] - Unable to add the resource at [/WEB-INF/classes/org/oasis_open/docs/wsrf/rp_2/jaxb.properties] to the cache for web application [cxf] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache

通常需将其设置为应用包大小,禁止设置为99999999超大值。

相关推荐
布莱克605几秒前
Swift 可选类型(Optionals)详解:从原理到实战
开发语言·安全·ssh·swift·optional·可选类型
学长毕设1 小时前
基于SpringBoot的景点管理系统-附源码
java·spring boot·后端
sxlishaobin2 小时前
Maven Setting详解
java·学习·maven
知守观2 小时前
一个方法两个触发口:反编译 XXL-Job 后,我看清了 inner/job 子包的裸奔现状
java·spring boot·微服务
用户3126874877202 小时前
CompletableFuture 链式编排:异步编程的优雅解法
java
瑞雪兆丰年兮2 小时前
JavaWeb-day14-SpringBootWeb原理篇
java·开发语言·spring boot·spring·bean·mybatis·javaweb
神仙别闹2 小时前
基于 Java GUI 贪心策略直接搜索算法和极大极小博弈树算法的智能人机博弈五子棋游戏
java·毕业设计·gui·贪心策略·极大极小博弈树
Flynn Liang3 小时前
RAG 评估体系:黄金集、检索指标与 LLM-as-Judge 落地
java·langchain·rag·评估·langchain4j·检索指标
SomeOtherTime4 小时前
Rust生命周期介绍(AI回答)
开发语言·后端·rust
程序猿打工仔4 小时前
计算机基础(C语言)考编、专技岗
c语言·开发语言·算法