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”.
In 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.
System.out.println("User id: " + userId + " at thread: " + Thread.currentThread().getId() + " current instance: " + this);
In 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.
Since I perform the request in an asynchronous mode, so the response of those five requests are processed and returned in parallel.
How 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.
The method loadServlet in class StandardWrapper will call constructor of my sample Servlet via reflection. All subsequent request will be served by this singleton.
Thread pool in Java Servlet
This thread pool behavior is easy to observe, just set breakpoint in doGet method in my Servlet, line 58:
Perform 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:
From the bottom of callstack we get the hint that those working threads are centrally managed by the Thread pool.
ICF 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:
Five debugger windows will pop up for the same time, each for one separate ABAP session where the request is handled.
From this source code we know the fact that in ABAP, the instance of handler class does not behave as singleton in Java Servlet.
From debugging we can observe that different session has different ICF handler instance which are isolated among each other.
Further 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
要获取更多Jerry的原创文章,请关注公众号"汪子熙":

ABAP SICF服务和Java Servlet的比较的更多相关文章
- Java Servlet规范
截自网址:http://blog.csdn.net/u010391029/article/details/46521051 JavaServlet Specification Version 2.3 ...
- Java Servlet完全教程
Servlet 是一些遵从Java Servlet API的Java类,这些Java类可以响应请求.尽管Servlet可以响应任意类型的请求,但是它们使用最广泛的是响应web方面的请求. Servle ...
- Java Servlet系列之Servlet生命周期
Servlet生命周期定义了一个Servlet如何被加载.初始化,以及它怎样接收请求.响应请求,提供服务.在讨论Servlet生命周期之前,先让我们来看一下这几个方法: 1. init()方法 在Se ...
- Java Servlet 技术简介
Java Servlet 技术简介 Java 开发人员兼培训师 Roy Miller 将我们现有的 servlet 介绍资料修改成了这篇易于学习的实用教程.Roy 将介绍并解释 servlet 是什么 ...
- java Servlet接口及应用
基本类和接口 一.javax.servlet.Servlet接口 servlet抽象集是javax.servlet.Servlet接口,它规定了必须由Servlet类实现由servlet引擎识别和管理 ...
- Java Servlet 工作原理问答
导读 本文来自stackoverflow的问答,讨论了Java Servlet的工作机制,如何进行实例化.共享变量和多线程处理. 问题:Servlet是如何工作的?Servlet 如何实例化.共享变量 ...
- 【Java】Java Servlet 技术简介
Java 开发人员兼培训师 Roy Miller 将我们现有的 servlet 介绍资料修改成了这篇易于学习的实用教程.Roy 将介绍并解释 servlet 是什么,它们是如何工作的,如何使用它们来创 ...
- java Servlet接口及应用(转)
基本类和接口 一.javax.servlet.Servlet接口 servlet抽象集是javax.servlet.Servlet接口,它规定了必须由Servlet类实现由servlet引擎识别和管理 ...
- JavaWeb之Java Servlet完全教程(转)
Servlet 是一些遵从Java Servlet API的Java类,这些Java类可以响应请求.尽管Servlet可以响应任意类型的请求,但是它们使用最广泛的是响应web方面的请求. Servle ...
随机推荐
- c++ 网络编程(五) LINUX下 socket编程 多种I/O函数 -以及readv和writev函数用法
原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/9614056.html 一.多种I/O函数 前言:之前我们讲的数据传输一般Linux上用writ ...
- CVE-2017-6920 Drupal远程代码执行漏洞学习
1.背景介绍: CVE-2017-6920是Drupal Core的YAML解析器处理不当所导致的一个远程代码执行漏洞,影响8.x的Drupal Core. Drupal介绍:Drupal 是一个由 ...
- 常用工具说明--Maven使用说明
什么是Maven? 如今我们构建一个项目需要用到很多第三方的类库,如写一个使用Spring的Web项目就需要引入大量的jar包.一个项目Jar包的数量之多往往让我们瞠目结舌,并且Jar包之间的关系错综 ...
- nodejs中cookie、session的使用
因为http会话的无状态性,为了标记用户的登录状态,便出现了cookie.cookie分为很多种,有普通cookie.签名cookie.json cookie等,这里主要记录下在express应用中如 ...
- the resource is not on the build path of a php project
打开工程里面的.project文件,确保里面的红色标记行都正确且存在,即可成功! <?xml version="1.0" encoding="UTF-8" ...
- 三、Host-Only(仅主机模式)
Host-Only模式其实就是NAT模式去除了虚拟NAT设备,然后使用VMware Network Adapter VMnet1虚拟网卡连接VMnet1虚拟交换机来与虚拟机通信的,Host-Only模 ...
- Python入门-初始面向对象
之前我们代码基本上都是面向过程的,今天我们就来初始一下python中一个重要的内容:面向对象 一.面向对象和面向过程(重点理解) 1.面向过程: 一切以事物的流程为核心. 核心是"过程&qu ...
- .NET开源工作流RoadFlow-流程运行-工作委托
如果某一个人某一段时间不在单位,则可以将自己的工作委托给他人代为处理. 在 流程处理-->工作委托 中可以管理自己的委托,管理员也可以在 流程管理-->工作委托 中管理所有人的委托: 委托 ...
- hdu 3613 Best Reward (manachar算法)
Best Reward Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Prob ...
- 09_dubbo服务发布原理
[ 启动服务的日志分析 ] 1.暴露本地服务 Export dubbo service com.alibaba.dubbo.demo.DemoService to local registry, du ...