In my application, the following situation: there is a тред типа А and a lot of тредов типа Б , in addition to this there is a main thread. In thread A, an error occurs, after which it is necessary immediately, or as soon as possible to close all threads B and the main thread, or to close threads B and transfer control to the main thread, which by some flag must understand what happened and take some actions before closing applications. Threads B must be closed as quickly as possible, because they run resource-intensive processes, the start of which becomes meaningless in case of an error in thread A.
Can someone from experienced developers give a beginner a variant of the algorithm (preferably with an example), when all this would be possible without using System.exit() ?