R
R
reus2017-05-23 13:45:35
Java
reus, 2017-05-23 13:45:35

How to make a time limit on the lifetime of a thread in Java?

How to make a time limit on the lifetime of a thread in Java?
I'm working with threads mostly with via array of threads + .join:

for (Advert adv : getAdverts()) {
      try {
        adv.join();
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

But sometimes the thread becomes eternal and the application freezes from .join.
Is it possible to somehow limit the lifetime of the thread (for example, 60 seconds) and how is it better to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hland, 2017-05-23
@Hland

Try invokeAll

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question