Running a continuous background task in Play 2.4.2

2019-09-02 17:36发布

I'm creating a web application that displays incoming events as strings onto the web browser. The events should be coming in from a listener that I have defined in another part of the program. These events will be emitted through a socket to the client side.

The problem: I need to keep the listener continually running in order to receive messages. The listener is essentially one block of code that's something like listener.run(), and it doesn't terminate. Right now, I am making a separate thread that runs this block of code and I have configured Global settings to run the thread on application startup.

I don't want my task to stop and start every time I refresh the page. How can I make the listener run right when the server starts?

1条回答
Anthone
2楼-- · 2019-09-02 18:11

Look at the Scheduling asynchronous tasks at the end of the doc: https://www.playframework.com/documentation/2.4.x/JavaAkka

查看更多
登录 后发表回答