[fpc-pascal] Threaded webserver and TJSONRPCModule instances: can I be sure there's only one?

Michael Van Canneyt michael at freepascal.org
Fri Oct 21 09:39:01 CEST 2022



On Fri, 21 Oct 2022, Luca Olivetti via fpc-pascal wrote:

> Hello,
>
> I'm using a TFPHTTPServerHandler in threaded mode.
> I'm also using a TJSONRpcModule.
> I see that, even if the calls come from different threads, only one instance 
> of the rpc module is ever created (on demand, the first time an rpc request 
> comes in) and used.
> Since I'm relying on this behaviour, can I be 100% sure it's by design and 
> not a quirk of my test setup?

It is controllable.

There is the 'Modulekind' : wkPooled.

Type
   TWebModuleKind = (wkPooled, wkOneShot{, wkSession});

And a property of your module:

  property Kind: TWebModuleKind read FWebModuleKind write FWebModuleKind default wkPooled;

wkPooled is the default, but if you explicitly set this to 'wkPooled' in the constructor, 
you'll be sure there is only ever 1 instance of the module, which is reused for 
every request...

Michael.


More information about the fpc-pascal mailing list