R
R
reus2017-05-25 13:00:20
Java
reus, 2017-05-25 13:00:20

What to do with processes that are left over from Java threads?

In general, I had a problem. It so happened that the application should run every minute and live for about 40 seconds. Judging by the logs (the logs come from stdout to the file), the application exits normally and without errors, BUT! htop shows the many processes of this application. As I understand it, these are threading processes.
And I noticed a feature, if I start the application simply:
java -jar /path/app.jar
then everything is fine. But if I add a task to cron:
* * * * * java -jar /path/app.jar
Then there is such trouble with threads.
The code works something like this:
1. main creates an instance of the ThreadList class and runs the .start() method
2. TreadList gets the class instances and calls

for (Advert adv : getAdverts()) {
      adv.start();
    }
    for (Advert adv : getAdverts()) {
      try {
        adv.join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

3. The Advert class extends Thread and performs the main logic. If it runs for too long, an exception is thrown and calls the interrupt() method.
Tell me, why can thread processes not end?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
ruslanys, 2017-06-01
@ruslanys

Why don't you launch threads inside the application? It is important to understand the difference between a process and a thread:
Not only that, running the JVM every 40 seconds also has its overhead.
It would be correct to run the application 1 time, and every 40 seconds it starts your `Advert` flows.
IMHO

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question