Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1330367
  • 博文数量: 932
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 10208
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-08 12:28
文章分类

全部博文(932)

文章存档

2021年(1)

2020年(134)

2019年(792)

2018年(5)

我的朋友

分类: 架构设计与优化

2019-04-19 17:22:43

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

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

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



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


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


阅读(502) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~