From 9d93fbf306f1892e82fbe9b731ae35af8a44385b Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Mon, 13 Jan 2025 14:44:40 +0100 Subject: [PATCH] threading_model.md: Add a general diagram visualizing application threads --- .../architectural_overview/threading_model.md | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/topics/basics/architectural_overview/threading_model.md b/topics/basics/architectural_overview/threading_model.md index ce7857f33..87bf6a5c9 100644 --- a/topics/basics/architectural_overview/threading_model.md +++ b/topics/basics/architectural_overview/threading_model.md @@ -15,8 +15,40 @@ In general, as in a regular [Swing](https://docs.oracle.com/javase%2Ftutorial%2F Its main purpose is handling UI events (such as reacting to clicking a button or updating the UI), but the platform uses it also for writing data. EDT executes events taken from the Event Queue. Operations performed on EDT must be as fast as possible to not block other events in the queue and freeze the UI. - There is only one EDT in the running application. -- background threads (BGT) – used for performing long-running and costly operations, or background tasks +- background threads (BGT) – used for performing long-running and costly operations, or background tasks. + +There is only one EDT and multiple BGT in the running application: + +```mermaid +--- +displayMode: compact +--- +gantt + dateFormat X + %% do not remove trailing space in axisFormat: + axisFormat ‎ + section EDT + UI task : 0, 1 + write : 3, 4 + UI task : 6, 7 + UI task : 7, 8 + write : 9, 10 + section BGT 1 + task : done, 0, 3 + task : done, 4, 6 + task : done, 7, 10 + section BGT 2 + task : done, 1, 2 + task : done, 3, 7 + task : done, 8, 10 + section ... + ‎ : 0, 0 + section BGT N + task : done, 0, 2 + task : done, 3, 6 + task : done, 7, 8 + task : done, 9, 10 +``` It is possible to switch between BGT and EDT in both directions. Operations can be scheduled to execute on EDT from BGT (and EDT) with `invokeLater()` methods (see the rest of this page for details).