goxr3plus / java-stream-player

🌌Java Advanced Audio Controller Library (WAV, AU, AIFF, MP3, OGG VORBIS, FLAC, MONKEY's AUDIO and SPEEX audio formats )
GNU General Public License v3.0
147 stars 33 forks source link

ExecutorService is not shut down #1

Open IARI opened 5 years ago

IARI commented 5 years ago

First of all thanks for the work on this project - works wonderfully.

I used it in a JavaFX application and noticed, that after calling Platform.exit(), the process was still running. It seems like the StreamPlayer class uses Java8 ExecutorService, but never shuts it down.

How about adding a public method to shut down the ExecutorServices ?

goxr3plus commented 5 years ago

Yess i should add more examples. You can call

player. stop() where player is your instance. Before you exit the application :)

You can also see the code of XR3Player which i have implemented everything and it is a JavaFX Media Player.

Keep me notified.

IARI commented 5 years ago

Hi and thanks for the quick reply :)

calling stop alone doesn't do it for me: the process keeps running. Currently I'm getting both private executors from the class via reflection like this (sorry, it's kotlin code)

    init {
        appCtl.exitHandler.add {
            log.info("Exit handler")
            stop()
            getExecutorService("streamPlayerExecutorService").shutdownNow()
            getExecutorService("eventsExecutorService").shutdownNow()
        }
    }

    private fun getExecutorService(fieldname: String) =
        StreamPlayer::class.java.getDeclaredField(fieldname).run {
            isAccessible = true
            get(streamPlayer) as ExecutorService
        }
goxr3plus commented 5 years ago

player. stop() doesn't work really? Like i am using it in my own app. How is that possible. Ah yes yes. You can exit your application with System.exit(-1) or 0

goxr3plus commented 5 years ago

Executors shutdown isn't promising to terminate just the second you call it.

TonalidadeHidrica commented 5 years ago

Maybe some wants the thread to be automatically halted right after all other threads finished. If the two (is it correct?) threads were daemon it would be helpful, so maybe adding daemon-thread option is one way.

goxr3plus commented 5 years ago

Yes that's a good idea 💡. Hm i am thinking how to code it m