java-stream-player icon indicating copy to clipboard operation
java-stream-player copied to clipboard

ExecutorService is not shut down

Open IARI opened this issue 6 years ago • 6 comments

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 ?

IARI avatar Mar 09 '19 12:03 IARI

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.

goxr3plus avatar Mar 09 '19 12:03 goxr3plus

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
        }

IARI avatar Mar 09 '19 12:03 IARI

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 avatar Mar 10 '19 11:03 goxr3plus

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

goxr3plus avatar Mar 10 '19 11:03 goxr3plus

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.

TonalidadeHidrica avatar May 03 '19 16:05 TonalidadeHidrica

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

goxr3plus avatar May 03 '19 18:05 goxr3plus