tinazheng
tinazheng

Reputation: 163

Running a continuous background task in Play 2.4.2 server

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?

Upvotes: 0

Views: 4146

Answers (1)

Leo
Leo

Reputation: 2189

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

Upvotes: 1

Related Questions