After a lot of digging, I found the right answer. I created a CallbackThreadInitilizer and used the Native.addCallbackThreadInitilizer method to associate it with each callback. This put them in one thread. If you have a ready-made answer, or you have some kind of flag that you send to indicate that this callback is the last, you can call Native.detatch (true) in this case, to disconnect the stream and let it be cleared gc. If you do not, it seems that you hold on for some time, and sometimes do new ones and close the old ones. I have never seen him hold more than three times.
source
share