2 years ago
#42793
ses
Unwanted garbage collection while calling from the method that ends
Spring Boot app, where Spring Boot's scheduled method calls RX method (rxjava3
) to do the long job (in separate thread pool).
@Scheduled(fixedDelay = ONE_SECOND)
public void init() {
process().subscribe(); // it returns Disposable
}
Imagine if process()
takes more than 1 second to finish, then the Disposable
(that process returns) stays "flying in the air" and could be destroyed by GC, and the process()
operation could be destroyed as well? (question 1)
I wonder what is the safe or standard approach. If one got similar worries.
(I do not want to use Job annotations or Quartz for that)
Sure, I can do process().blockingGet()
, but that would block my main thread, and possibly interfere with @Scheduled
(not sure). So I want to be explicit - saying: "hey, I am not blocking anything, just launching the processes here."
var disposable = process().subscribe()
this.processDisposables.add(disposable)
- would this do the trick?
This way my Spring service would always have a link to disposable. So GC would not dare to collect? (question 2)
But then I could end up having infinite amount of those links in that list. And would need to think about cleaning them. (and maybe can lead to memory leaks)
Let me know what you think. Is there a better approach? (question 3)
update (to save on comments):
yes I, "want a process that lasts more than 1 second to complete and then be disposed"
java
spring-boot
rx-java
rx-java3
0 Answers
Your Answer