ABAP function group和Tomcat library重复加载问题

时间:2022-06-01
本文章向大家介绍ABAP function group和Tomcat library重复加载问题,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

ABAP

ABAP help文档里对**LOAD-OF-PROGRAM"的关键字是这样描述的:

This event keyword defines the program constructor of an executable program, a module pool, a function group, or a subroutine pool. The program constructor is an event block whose event is raised by the ABAP-runtime environment when one of the executable programs mentioned above is loaded into the internal session.

以Function group为例,每当一个function group里的任意一个function module第一次被调用时,对应的ABAP program被加载到internal session里,同时ABAP运行时抛出LOAD-OF-PROGRAM, 执行应用程序员编写的事件处理逻辑。

现在我有一个名为ZTOMCAT的function group。其LOAD-OF-PROGRAM就负责弹出调试器。

我有两个report。Report 2的源代码:

REPORT ZJERRY_RE2.

call FUNCTION 'ZTEST_FM_1'.

Report 1:

CALL FUNCTION 'ZTEST_FM_1'.

SUBMIT zjerry_re2 AND RETURN.

那么我执行report1,断点会触发一次还是两次?

答案是两次。

LOAD-OF-PROGRAM在这种场景下的行为,ABAP help已经说的很清楚了:

When a program is called using SUBMIT or using a transaction code, a new internal session is opened in every call and the event block is executed once in every call.

每次program通过SUBMIT或者事务码的方式调用时,会起一个新的internal session,在此新的session里LOAD-OF-PROGRAM会触发一次。

下图也直观表明了每次调用SUBMIT( calling programs)时会新起一个Internal Session。

Tomcat 库文件的重复加载问题

我的pom.xml里定义了一个gson的依赖关系,ABAPer可以把其类比成在我的Java代码里调用Google提供的gson API。

打成war包之后,该库文件位于WEB-INF/lib文件夹下。

那么如果我有多个Web应用都用到了gson, 则每个应用的WEB-INFlib文件夹下面都有gson的jar文件。

问题:在运行时,Tomcat只会将一份gson.jar的内容加载到内存么?

答案是不会。根据Tomcat的官方文档,Tomcat会为每个Web应用创建一个专属的ClassLoader实例,每个应用的WEB-INFlib下的资源,对于其他应用来说不可见,彼此隔离。

当然如果想只用一份库文件,可以把它放到目录 tomcat-installation-directory/common/lib下面。更多细节参考stackoverflow上的讨论.

要获取更多Jerry的原创技术文章,请关注公众号"汪子熙"或者扫描下面二维码: