public class ResponseCommunicator
{
private Logger logger = Logger.getLogger(ResponseCommunicator.class);
private Timer timer = null;
private long interval = 60000;
public ResponseCommunicator()
{
}
public ResponseCommunicator(long interval)
{
this.interval = interval;
}
/*public void start(final HttpServletResponse res)
{
timer = new Timer();
timer.schedule(new TimerTask()
{
@Override
public void run()
{
try
{
PrintWriter pw = res.getWriter();
pw.write("");
pw.flush();
}
catch (Exception e)
{
logger.error("Failed to communicate with client", e);
}
}
}, interval/2, interval);
}*/
public void start(final HttpServletResponse res)
{
timer = new Timer();
timer.schedule(new TimerTask()
{
@Override
public void run()
{
try
{
OutputStream os = res.getOutputStream();
os.write("".getBytes());
os.flush();
}
catch (Exception e)
{
logger.error("Failed to communicate with client", e);
}
}
}, interval/2, interval);
}
public void stop()
{
if (timer != null)
{
timer.cancel();
timer.purge();
}
}
}
java decompilation tool and handling request time out
最新推荐文章于 2019-08-08 15:05:17 发布
本文详细介绍了响应通信器类的实现,包括初始化、开始通信、停止通信等方法,并通过异常处理确保通信过程的稳定性。
1837

被折叠的 条评论
为什么被折叠?



