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

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

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


相关文章
JavaWeb-Servlet服务连接器(三)
Response响应对象、1.基本功能、2.重定向、3.路径、4.服务器输出数据到浏览器
65 2
|
存储 XML JSON
JavaWeb-Servlet服务连接器(四)
1.ServletContext Cookie与Session 1.Cookie 2.Session
56 0
|
存储 Java 应用服务中间件
JavaWeb-Servlet服务连接器(二)
Request(获取请求信息)、1.获取请求行内容、2.解决乱码问题、3.获取请求头部分、4.获取请求体、5.其他功能
54 0
|
XML 前端开发 Java
关于服务连接器(Servlet)你了解多少?
Servlet是JavaWeb最为核心的内容,它是Java提供的一门动态web资源开发技术。 使用Servlet就可以实现,根据不同的登录用户在页面上动态显示不同内容。 Servlet是JavaEE规范之一,其实就是一个接口,将来我们需要定义Servlet类实现Servlet接口,并由web服务器运行Servlet
69 0
关于服务连接器(Servlet)你了解多少?
|
JavaScript 前端开发 Java
SAP ABAP SICF服务和Java Servlet的比较
SAP ABAP SICF服务和Java Servlet的比较
145 0
SAP ABAP SICF服务和Java Servlet的比较
SAP ABAP SICF事务码和SAP Hybris的链式过滤器filter chain
SAP ABAP SICF事务码和SAP Hybris的链式过滤器filter chain
102 0
SAP ABAP SICF事务码和SAP Hybris的链式过滤器filter chain
|
Java Spring
SAP ABAP SICF事务码和SAP Hybris的链式过滤器filter chain
SAP ABAP SICF事务码和SAP Hybris的链式过滤器filter chain
236 0
SAP ABAP SICF事务码和SAP Hybris的链式过滤器filter chain
|
JavaScript 前端开发 Java
ABAP SICF服务和Java Servlet的比较
ABAP SICF服务和Java Servlet的比较
104 0
|
5月前
|
前端开发 搜索推荐 开发者
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
|
5月前
|
JavaScript 前端开发 开发者
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍
下一篇
无影云桌面