Answer the question
In order to leave comments, you need to log in
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();
}
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question