You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2022/07/11 02:22:52 UTC

[servicecomb-docs] branch master updated: HTTP-Filter章节添加获取线程上下文的注意事项 (#273)

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-docs.git


The following commit(s) were added to refs/heads/master by this push:
     new 046b0b4  HTTP-Filter章节添加获取线程上下文的注意事项 (#273)
046b0b4 is described below

commit 046b0b404a91ba831dcf72303baa88e60bb3ef08
Author: yanghao <73...@users.noreply.github.com>
AuthorDate: Mon Jul 11 10:22:49 2022 +0800

    HTTP-Filter章节添加获取线程上下文的注意事项 (#273)
---
 .../en_US/docs/general-development/http-filter.md                  | 7 +++++++
 .../zh_CN/docs/general-development/http-filter.md                  | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/java-chassis-reference/en_US/docs/general-development/http-filter.md b/java-chassis-reference/en_US/docs/general-development/http-filter.md
index 5ce0dd1..810f1a0 100644
--- a/java-chassis-reference/en_US/docs/general-development/http-filter.md
+++ b/java-chassis-reference/en_US/docs/general-development/http-filter.md
@@ -18,6 +18,13 @@ Both HttpClientFilter and HttpServerFilter allow multiple loads:
 
 Whether it is request or response, read the body stream, use getBodyBytes\ (\), the return value may be null (such as scenario of getting an invocation), if not null, the corresponding stream length, Obtain through getBodyBytesLength\ (\ ).
 
+>***Tips***: 
+>The beforeSendRequest of HttpClientFilter is executed in the current thread of the interface call, and the afterReceiveResponse is executed in the business thread pool.
+>
+>The afterReceiveRequest of HttpServerFilter is executed in the business thread pool, beforeSendResponse and beforeSendResponseAsync may be executed in the business thread pool or the network thread pool. Make sure that blocking operations can not occur.
+>
+>The bottom layer of Java Chassis is an asynchronous framework, with frequent thread switching. When the business extends Filter, if it involves obtaining the thread context through ThreadLocal, the acquisition may be empty. For this scenario, it is recommended to use InhritableThreadLocal instead of ThreadLocal to store data, or to use extended Handler instead of Filter.
+
 # 2.HttpClientFilter
 
 The system has two built-in HttpClientFilter. Note that the order value does not conflict when extending the function:
diff --git a/java-chassis-reference/zh_CN/docs/general-development/http-filter.md b/java-chassis-reference/zh_CN/docs/general-development/http-filter.md
index 8c42498..b957ef1 100644
--- a/java-chassis-reference/zh_CN/docs/general-development/http-filter.md
+++ b/java-chassis-reference/zh_CN/docs/general-development/http-filter.md
@@ -20,6 +20,8 @@ null(比如get调用的场景),如果不为null,对应的码流长度,
 >HttpClientFilter 的 beforeSendRequest 在接口调用的当前线程执行, afterReceiveResponse 在业务线程池中执行。
 >HttpServerFilter 的 afterReceiveRequest 在业务线程池中执行,beforeSendResponse 和 beforeSendResponseAsync
 >可能在业务线程池执行, 也可能在网络线程池执行, 务必保证不能够出现阻塞操作。
+>
+>Java Chassis底层是异步框架,线程切换频繁。当业务扩展Filter时,若涉及通过ThreadLocal获取线程上下文时,可能会出现获取为空的情况。针对这种场景,建议使用InHeritableThreadLocal来代替ThreadLocal存储数据,或者使用扩展Handler的方式来代替Filter。
 
 ## HttpClientFilter