# Configure Tuning Threads

Thread tuning is an important part of preparing the **WildFly application server** for running ONEWEB efficiently. Proper tuning ensures that the server can handle concurrent requests, background jobs, and integrations without performance degradation.

WildFly uses a **subsystem‑based configuration model**, where each subsystem provides a specific set of capabilities such as EE, EJB, IO, and web handling. A **profile** is a named collection of these subsystems along with their configuration.

***

#### Key WildFly Subsystems Involved in Thread Tuning

**EE Subsystem**

The **EE subsystem** provides common Java EE functionality and includes support for managed executor services.

A **managed executor service** controls how application tasks are executed in parallel. Important configuration attributes include:

* **context-service** – Context service used by the executor
* **core-threads** – Minimum number of threads; should be greater than zero
* **max-threads** – Maximum number of threads allowed
* **queue-length** – Task queue capacity
* **keepalive-time** – Idle time before excess threads terminate
* **hung-task-threshold** – Time (ms) before a task is considered hung
* **long-running-tasks** – Hint for long‑running workloads
* **reject-policy** – Behavior when tasks are rejected
* **thread-factory** – Thread factory used by the executor

These settings directly impact request throughput and background processing behavior.

***

**IO Subsystem**

The **IO subsystem** controls low‑level I/O operations and thread pools used by other subsystems.

Key components include:

**Worker**

* **io-threads** – Number of I/O threads (default: `CPU count × 2`)
* **task-max-threads** – Maximum worker threads (default: `CPU count × 16`)
* **task-keepalive** – Idle time for non‑core threads
* **stack-size** – Stack size for worker threads

**Buffer Pool**

* **buffer-size** – Size of each buffer slice
* **buffers-per-slice** – Number of buffers per slice
* **direct-buffers** – Whether direct buffers are used

If not explicitly set, WildFly calculates optimal values based on available system resources.

***

#### CPU Cores and Threads

A **CPU core** is an individual processing unit within a processor. Modern servers typically use multi‑core CPUs, allowing parallel execution of threads.

Threads represent concurrent execution paths within an application. WildFly and the JVM rely heavily on multi‑threading to:

* Process multiple user requests simultaneously
* Run background jobs and schedulers
* Handle I/O and integration tasks

Proper thread configuration must consider both **CPU core count** and expected concurrency.

{% hint style="info" %}
**Note:** “Core” also refers to Intel’s processor branding (Core i3, i5, i7, etc.), which is unrelated to the concept of CPU cores used in thread tuning.
{% endhint %}

***

#### JVM Options and Memory‑Related Tuning

Thread performance is closely related to JVM memory configuration. Common JVM options include:

* **`-Xms`** – Initial heap size
* **`-Xmx`** – Maximum heap size
* **`-Xss`** – Thread stack size

For example:

* `-Xms2048m` sets an initial heap size of 2 GB
* `-Xmx2048m` caps the heap at 2 GB

Heap sizing should be aligned with:

* Number of concurrent threads
* Application complexity
* Transaction volume

***

#### PermGen / Metaspace Considerations

In older JVM versions, **PermGen** stored class metadata and string pools.\
In **Java 8 and later**, PermGen has been replaced by **Metaspace**, and PermGen‑specific options no longer apply.

***

#### Handling OutOfMemory Errors

For production environments, it is recommended to enable heap dump generation:

* `-XX:+HeapDumpOnOutOfMemoryError`
* `-XX:HeapDumpPath=<path>`

Optional recovery actions:

* `-XX:OnOutOfMemoryError="shutdown -r"`

Heap dumps can be large (GBs), so ensure sufficient disk space is available.

***

#### Class Loading Diagnostics

For troubleshooting memory or classloader issues, the following JVM options can be useful:

* `-XX:+TraceClassLoading`
* `-XX:+TraceClassUnloading`

These options log class load/unload events and help identify classloader leaks.

***

#### Recommended Baseline Configuration for ONEWEB

The following diagram illustrates a **recommended standard configuration** for running ONEWEB on WildFly:

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2F8XASTskZGx5IXzT9PA0i%2Fimage.png?alt=media&#x26;token=9704ed12-f6db-43c9-b0ce-7effa6508479" alt=""><figcaption></figcaption></figure>

This configuration provides a balanced starting point and can be adjusted based on workload, concurrency, and performance testing results.

***

#### Summary

* WildFly thread tuning relies on **EE and IO subsystems**
* CPU cores, thread counts, and JVM options must be aligned
* Default values are often sufficient but may require tuning for high‑load systems
* Proper tuning improves stability, throughput, and scalability of ONEWEB

Thread tuning should be revisited as system usage grows or application complexity increases.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onewebstack.com/oneweb-platform-th/getting-started/platform-configuration/platform-components-overview-and-management/prepare-prerequisite-software/prepare-application-server/configure-tuning-threads.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
