Skip to main content
Version: 20

Using preemptive web processes

The 4D Web Server allows you to take full advantage of multi-core computers by using preemptive web processes in your applications. You can configure your web-related code, including 4D tags, web database methods or ORDA REST class functions to run simultaneously on as many cores as possible.

For in-depth information on preemptive process in 4D, please refer to the Preemptive 4D processes section in the 4D Language Reference.

Availability of preemptive mode for web processes

The following table indicates whether the preemptive mode is used or is available, depending on the execution context:

4D ServerInterpreted (debugger attached)Interpreted (debugger detached)Compiled
REST Servercooperativepreemptivepreemptive
Web Servercooperativecooperativeweb setting
Web Services Servercooperativecooperativeweb setting
4D remote/single-userInterpretedCompiled
REST Servercooperativepreemptive
Web Servercooperativeweb setting
Web Services Servercooperativeweb setting

Writing thread-safe web server code

All 4D code executed by the web server must be thread-safe if you want your web processes to be run in preemptive mode. When the preemptive mode is enabled, the following parts of the application will be automatically evaluated by the 4D compiler:

For each of these methods and code parts, the compiler will check if the thread-safety rules are respected, and will return errors in case of issues. For more information about thread-safety rules, please refer to the Writing a thread-safe method paragraph in the Processes chapter of the 4D Language Reference manual.

Thread-safety of 4D web code

Most of the web-related 4D commands and functions, database methods and URLs are thread-safe and can be used in preemptive mode.

4D commands and database methods

All 4D web-related commands are thread-safe, i.e.:

  • all commands from the Web Server theme,
  • all commands from the HTTP Client theme.

The web-related database methods are thread-safe and can be used in preemptive mode (see above): On Web Authentication, On Web Connection, On REST Authentication...).

Of course, the code executed by these methods must also be thread-safe.

Web Server URLs

The following 4D Web Server URLs are thread-safe and can be used in preemptive mode:

  • 4daction/ (the called project method must also be thread-safe)
  • 4dcgi/ (the called database methods must also be thread-safe)
  • 4dwebtest/
  • 4dblank/
  • 4dstats/
  • 4dhtmlstats/
  • 4dcacheclear/
  • rest/
  • 4dimgfield/ (generated by PROCESS 4D TAGS for web request on picture fields)
  • 4dimg/ (generated by PROCESS 4D TAGS for web request on picture variables)

Preemptive web process icon

Both the Runtime Explorer and the 4D Server administration window display a specific icon for preemptive web processes:

Process typeIcon
Preemptive web method