I am using ServerSocket in my java application and it will be listening to port 1111. When the client connects to the port each client connection will be executed in separate Thread. Each connection will receive data for every 1 minute until the connection is closed.
The question is, suppose if the client connection doesn't receive any data for more than 10 minutes some event should be triggered and the important thing is connection should remain unclosed. So that i can use that event to execute an mail alert to me.
Is there any technique to do this?
You can implement a Listener
or Observer
Interface. Here is the algorithm. Create a Thread, eg., ClientMonitor
which polls a flag in the client object. You can also use a TimerTask
to poll the flag/object at specified time intervals
TimerTask
to monitor the client TimerTask
. Exception
, which will take care of executing the mail alert while the connection to the client remains open. TimerTask
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.