Structured concurrency:
a simple principle that states that when the flow of execution splits into multiple concurrent flows, they rejoin in the same code block.
Based on this, let's assume I have something like below:
//can replace this with Virtual thread
public static void delegateTask() {
Thread delegator = new Thread(new TaskDeligator());
delegator.setName("TaskDeligatorThread");
logger.info("Creating task delegator thread....which will register listeners");
delegator.start();
}
Question 1: I have created a new child thread(TaskDeligatorThread) but did not finish/end/rejoin in the same code block i.e. the method delegateTask() - does this mean it's not following structured concurrency principle?
Question 2: There might be scenarios where Thread1 wants to delegate some task to a child thread (which Thread1 will create) and Thread1 doesn't need to wait for the output/completion of the child thread. In this case, again I will not finish/end/rejoin the child thread in the code block where the child thread was created. In these kind of scenarios how would I follow structured concurrency?