[英]Delphi/Indy multithreading Server
I am trying to turn my app multithreading.我正在尝试将我的应用程序变成多线程。 What I want to achieve is: - Receive command via TidHTTPServer - Execute local action (might involve using tidHTTP to send/receive data to other services) - return execution result to the original caller
我想要实现的是: - 通过 TidHTTPServer 接收命令 - 执行本地操作(可能涉及使用 tidHTTP 向其他服务发送/接收数据) - 将执行结果返回给原始调用者
since I am pretty new to multi-threading I would like to know if my design-idea is correct因为我对多线程很陌生,所以我想知道我的设计理念是否正确
will this work?这会起作用吗?
THTTPServer
is a multi-threaded component. THTTPServer
是一个多线程组件。 Its OnCommand...
events are fired in the context of worker threads that Indy creates for you.它的
OnCommand...
事件在 Indy 为您创建的工作线程的上下文中触发。
As such, you do not need to derive your TMsgHandler
from TThread
.因此,您不需要从
TThread
派生TMsgHandler
。 Do your TIdHTTP
directly in the context of the OnCommand...
thread instead.直接在
OnCommand...
线程的上下文中执行TIdHTTP
。 A response will not be sent back to the client until your event handler exits (unless you send one manually).在您的事件处理程序退出之前,不会将响应发送回客户端(除非您手动发送)。 However, you should not share a single
TIdHTTP
from the main thread (unless you absolute need to, in which case you would need to synchronize access to it).但是,您不应从主线程共享单个
TIdHTTP
(除非您绝对需要,在这种情况下您需要同步对它的访问)。 You should create a new TIdHTTP
dynamically directly in your OnCommand...
/ TMsgHandler
code as needed.您应该根据需要直接在
OnCommand...
/ TMsgHandler
代码中动态创建一个新的TIdHTTP
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.