5

I have a situation in which an my Android application is not able to perform a soft real time task well in time as Garbage Collector is called which takes a few milliseconds. The few ms of time given to GC is inadequate to miss some important deadline for small tasks of reading data from IO device.

I was thinking about introducing another thread and giving it the task of polling the important data. However I'm not sure if GC suspends all threads or just the memory hogging ones?

sharjeel
  • 5,825
  • 7
  • 34
  • 49

1 Answers1

9

In Memory Management for Android Apps by Patrick Dubroy I found the following (slide 16, emphasis mine):

  • Pre-Gingerbread GC:

    • Stop-the-world

    • Full heap collection

    • Pause times often > 100ms

  • Gingerbread and beyond:

    • Concurrent (mostly)

    • Partial collections

    • Pause times usually < 5ms

In general, garbage collection must stop the whole VM, although nowadays this time greatly reduced. However neither VM nor Android platform as a whole are not real-time operating systems so don't expect such strict guarantees.

Why do you need single millisecond precision?

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • I am getting a stream of system events from the kernel. If the stream is not read in time, the events are dropped. Garbage Collection pausing the VM can be troublesome for me. I'm not sure about the exact time threshold above which it'll be problematic but 100 ms is surely too high. 5 ms may or may not be problematic; I'll have to do some experimentation. Thanks. – sharjeel Dec 03 '12 at 23:29