I have a time critical application that needs to send a UDP datagram on a set schedule. The tolerance for jitter is very low on the receiving side. Implementing this with a java ScheduledThreadPoolExecutor isn't adequate because when the GC does a "Stop the World" collection my thread pauses while the GC does it's job.
I would like to implement the business logic in Java while implementing the time critical portions with POSIX threads in C++ (Native environment is Linux by the way). This would allow us to save thousands of lines of code written in Java and also get the pacing we need from the native system calls.
My question is this: If I call a JNI function that creates a separate POSIX thread will that thread be "paused" when the Java GC does a "Stop the World" collection? Are there any pitfalls that an experienced JNI guru would like to point out with this approach or any alternative approaches one would suggest?
As always, thanks to the awesome stack overflow community!
They all block the running threads occasionally when they need to do global GC. The concurrent GC does try to do most of its work in a concurrent fashion though.
4) Garbage Collection in Java is carried by a daemon thread called Garbage Collector. 5) Before removing an object from memory garbage collection thread invokes finalize() method of that object and gives an opportunity to perform any sort of cleanup required.
No thread (or the things it refers to) will be garbage-collected while it is still running. Save this answer.
When Java programs run on the JVM, objects are created on the heap, which is a portion of memory dedicated to the program. Eventually, some objects will no longer be needed. The garbage collector finds these unused objects and deletes them to free up memory.
My question is this: If I call a JNI function that creates a separate POSIX thread will that thread be "paused" when the Java GC does a "Stop the World" collection?
It will have no effect. STW affects java threads that needs to arrive to a safe point. A java thread into native code won't be affected either.
It shouldn't block the posix thread (assuming that the gc doesn't use so much cpu that other system calls would be blocked). I would think that it would block access to the posix thread from the java application but only for a very limited time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With