B
B
baalmor2013-10-07 19:09:37
Java
baalmor, 2013-10-07 19:09:37

How to perform an action after a delay in netty-socketio?

Hello.
I am writing a service in Java using this wonderful library.
github.com/mrniko/netty-socketio
Faced the following problem. Users connect to the service and for each of them, I need to count thirty seconds, and then perform some action.
To be honest, I have no idea how to approach this task.
The java timer seems to be executed by a separate thread, but I don’t have enough experience how to connect this timer with the event model of this library. As I understand it, in this library, incoming data is processed by a separate thread and passed to functions - listeners, which also spin in separate threads. I see the solution in simulating the arrival of data from the timer thread and passing the event to be processed every second. But the sixth sense tells me that there must be a way easier and also multi-threaded.
Actually the question is, how do such tasks usually solve in java? What are the options to solve this problem using this library?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Yarosh, 2013-12-09
@baalmor

This is done in Java through the ScheduledExecutorService.
In the library, this is implemented this way and that way
. In general, I advise you to deal with the contents of the java.util.concurrent package.
Actually, I advise you to look at Atmosphere - it integrates perfectly into Play2 / Grails, and overall support is better. There are no problems with Socket.io.

D
Dmitry Zaitsev, 2013-10-07
@dim_s

Yes, the timer code is executed by a separate thread, most likely you need to create a new timer class, in the constructor of which you can pass SocketIOClient clientand save in the timer property, then you can send messages from the timer event to the client if it has not yet disconnected. Only now you need to find out if the SocketIOClient class is thread-safe or not.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question