Closed HeeJoon-Kim closed 1 year ago
This comes up from time to time.
Some related discussion in:
Essentially, the threads are due to vlcj's use of JNA, and it is how JNA handles callback events (among other things I suppose) from native VLC code back into Java code.
This is why it is more apparent when you are using lots of events.
The "media-player-events" thread is the name vlcj tells JNA to use for these threads.
The last time I looked at this, I did a LOT of profiling and such, and the results are summarised in one or other of those related issues.
IIRC the basics of it is that just because you see so many Thread instances, it does not actually mean new threads are continually being created since JNA does some cleverness behind the scenes.
It has been a while since I last looked at this, but if someone can point to a specific problem with vlcj not using JNA correctly, I will take another look.
I suppose a follow-up is, despite the seemingly increasing instance counts, are you actually seeing real memory leaks after the GC has run?
Thanks for quick answer!!
I'm not sure about memory leaks.. I will watch a few days and report it.~!!
Just a note for the future, this problem (if it is a problem) will eventually go away with JDK 21 (or maybe later) when the FFM API is finalised since JNA will no longer be used.
A quick test with vlcj-5.0.0 (currently in development)...
I can't recall any significant differences around vlcj-4.8.x and vlcj-5.x.
This test plays new media every 5 seconds.
No event listener:
Event listener added for media changed events:
Looks to be working normally, the absolute number of threads is stable.
Using 4.8.2 and the same test, it was stable but with one seemingly "extra" media-player-events thread from time-to-time:
But it was stable, it was not continually increasing.
btw, if you are going to duplicate the media ref, I think you should do it OUTSIDE of the submit call. The media ref param is only valid for the duration of the method call, and submit will run later in a different thread, potentially after the callback method has already returned.
I also think your call to get the list from the player is potentially racy since you are putting it into a separate thread that will run some time later.
In fact, you should only use submit() if you are going to do something that interacts with the native media player, I am not sure you really need to use it given the code I can see above.
Closing due to lack of follow-up, if you have more details to add this can be re-opened.
Hello!
I have a question about something strange while running vlcj in SpringBoot..
First event run on "http-nio-8181-exec-1" thread, but next event run on "media-player-events"... And the "media-player-events" thread keeps "running" without interruption. Also, when an event occurs, the "media-player-events" thread is incremented by one.
vlcj version is 4.8.2 and heare is a code..
My question is.... How to handle events without the "media-player-events" thread being spawned? Thanks..!!