Java: Templates for monitoring workflows?

and excuse the lack of knowledge about multithreaded applications, but I'm new to this field.

Is there a template or common methodology used to monitor the “job completion” or “job status” of workflows from the monitor (a class that acts like a monitor)?

I am currently creating a list of workers and creating one thread for each worker. After all the threads are started, I iterate over the worklist and check their status by making a method call.

At that time, I could not come up with another solution, but as a newcomer to the field, I do not know if this is suitable, or if there are other solutions or templates that I should study.

+3
source share
3 answers

, , .

, (.. , , , ), Thread.join():

try {
    for (Thread t: threadsIWaitOn)
        t.join();
} catch (InterruptedException iex) {
     /* ... handle error ... 
}

, , Thread.getState(). Thread.State, , , , .., Javadoc , , . , .

, , , 0 100 , Map Thread to AtomicInteger , AtomicInteger . , , , .

, , , . , - !

+2

ThreadPool Executor, Future < > , . : Java Concurrency

+2

Try using any synchronization. For example, wait on some monitor / semaphore until the work is done / what you need.

+1
source

Source: https://habr.com/ru/post/1785637/


All Articles