SAP ABAP SICF服务和Java Servlet的比较-阿里云开发者社区

开发者社区> c位出道> 正文

SAP ABAP SICF服务和Java Servlet的比较

简介: SAP ABAP SICF服务和Java Servlet的比较
+关注继续查看

In my opinion ABAP ICF handler and Java Servlet play the same role in enhancement which enables your web server with additional functionality.


This blog will not introduce how an ICF handler class in ABAP or a Servlet in Java are developed, but focus the way those instances of handler class or Servlet are spawned by Web Server.


Let’s first study the Servlet spawn behavior in Java.


Servlet in Java

According to Servlet specification, http request against a given url will be served by the same single instance of servlet.


For example, I have developed a simple Servlet which just returns “Hello world” as response. I map it with url starting with “/Hello”.



image.pngIn the doGet method, I print out the current thread id and instance address to try to verify if every request is served with the SAME servlet instance.


image.pngIn client side I use jQuery to send out five different request simultaneously:var LOCAL = "http://localhost:9098/JerryServlet/Hello?userId=";

var PREFIX = "i04241";

function main() {

 for( var i = 0; i < 5; i++) {

     var url = LOCAL + PREFIX + i;

     var html = getPostByAJAX(url);

    console.log("response: " + html);

 }

}

$(function(){  

main();

});  

function getPostByAJAX(requestURL){

  var html = $.ajax({

  url: requestURL, async: true}).responseText;  

  return html;

}When executing the client JavaScript code, I observe in Server console and could find out that these five requests are handled by the same Servlet instance ,however in different threads.

image.png

Since I perform the request in an asynchronous mode, so the response of those five requests are processed and returned in parallel.image.pngHow singleton behavior of Servlet is achieved

The instance of requested Servlet will only be initialized when it is asked for the first time. The below two-fold instance checking against null is a typical thread-safe implementation pattern for Singleton in Java.


image.pngThe method loadServlet in class StandardWrapper will call constructor of my sample Servlet via reflection. All subsequent request will be served by this singleton.



image.png

Thread pool in Java Servlet

This thread pool behavior is easy to observe, just set breakpoint in doGet method in my Servlet, line 58:image.pngPerform the client code to send five requests, then in Eclipse we can see the five working threads stopped at the breakpoint at the same time:


image.pngFrom the bottom of callstack we get the hint that those working threads are centrally managed by the Thread pool.image.pngICF Handler class in ABAP

Create a simple ICF service in tcode SICF and implement its handler class.

Set a breakpoint on method HANDLE_REQUEST, then trigger the request sending in client code:


image.pngFive debugger windows will pop up for the same time, each for one separate ABAP session where the request is handled.image.pngFrom this source code we know the fact that in ABAP, the instance of handler class does not behave as singleton in Java Servlet.

image.pngFrom debugging we can observe that different session has different ICF handler instance which are isolated among each other.

image.pngFurther reading

I have written a series of blogs which compare the language feature among ABAP, JavaScript and Java. You can find a list of them below:


Lazy Loading, Singleton and Bridge design pattern in JavaScript and in ABAP

Functional programming – Simulate Curry in ABAP

Functional Programming – Try Reduce in JavaScript and in ABAP

Simulate Mockito in ABAP

A simulation of Java Spring dependency injection annotation @Inject in ABAP

Singleton bypass – ABAP and Java

Weak reference in ABAP and Java

Fibonacci Sequence in ES5, ES6 and ABAP

Java byte code and ABAP Load

How to write a correct program rejected by compiler: Exception handling in Java and in ABAP

An small example to learn Garbage collection in Java and in ABAP

String Template in ABAP, ES6, Angular and React

Try to access static private attribute via ABAP RTTI and Java Reflection

Local class in ABAP, Java and JavaScript

Integer in ABAP, Java and JavaScript

Covariance in Java and simulation in ABAP

Various Proxy Design Pattern implementation variants in Java and ABAP

Tag(Marker) Interface in ABAP and Java

Bitwise operation ( OR, AND, XOR ) on ABAP Integer

ABAP ICF handler and Java Servlet

ADBC and JDBC

CL_ABAP_CORRESPONDING, CL_JAVA_CORRESPONDING and CL_JS_CORRESPONDING

Build an Cross Site Scripting example in Java and ABAP

Play around with JSONP in nodeJS server and ABAP server


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
IOS 使用KBMMW 访问JAVA 服务
废话少说,如何使用KBMMW 做个过渡,使IOS 可以使用JAVA 的服务? 其实KBMMW 本身就要java service 的服务,但是为了把这个问题说清楚,我手工做一个例子。   首先,要使用JAVA 服务,JRE 是肯定要安装的。
819 0
阿里云服务器怎么设置密码?怎么停机?怎么重启服务器?
如果在创建实例时没有设置密码,或者密码丢失,您可以在控制台上重新设置实例的登录密码。本文仅描述如何在 ECS 管理控制台上修改实例登录密码。
10093 0
阿里云服务器如何登录?阿里云服务器的三种登录方法
购买阿里云ECS云服务器后如何登录?场景不同,大概有三种登录方式:
2963 0
阿里云服务器端口号设置
阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
10886 0
Linux下执行Java服务程序
nohup命令 普通进程用&amp;符号放到后台运行,如果启动该程序的控制台logout,则该进程随即终止。 要实现守护进程,一种方法是按守护进程的规则去编程(本站有文章介绍过),比较麻烦;另一种方法是仍然用普通方法编程,然后用nohup命令启动程序: nohup &lt;程序名&gt; &amp; 则控制台logout后,进程仍然继续运行,起到守护进程的作用(虽然它不是严格意义上的守护进程)
1268 0
阿里云服务器如何登录?阿里云服务器的三种登录方法
购买阿里云ECS云服务器后如何登录?场景不同,阿里云优惠总结大概有三种登录方式: 登录到ECS云服务器控制台 在ECS云服务器控制台用户可以更改密码、更换系.
13893 0
+关注
2316
文章
0
问答
来源圈子
更多
+ 订阅
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载