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

ABAP

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

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.html

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

如今我有一个名为ZTOMCAT的function group。其LOAD-OF-PROGRAM就负责弹出调试器。程序员

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

REPORT ZJERRY_RE2.

call FUNCTION 'ZTEST_FM_1'.

Report 1:apache

CALL FUNCTION 'ZTEST_FM_1'.

SUBMIT zjerry_re2 AND RETURN.

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

答案是两次。 session

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

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-INF\lib文件夹下面都有gson的jar文件。

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

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

固然若是想只用一份库文件,能够把它放到目录 [tomcat-installation-directory]/common/lib下面。更多细节参考stackoverflow上的讨论.

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

相关文章
相关标签/搜索