Java:底端上送心跳时线程继续执行,若超过5秒未上送心跳则线程中断
PHP中文网
PHP中文网 2017-04-18 09:16:17
0
3
360

不用贴代码,赐我点儿思路就可以,我只会设置线程超时,但是底端上送心跳时这个线程应该是不受影响继续执行的,设置了超时时间,就算心跳上来了到了超时时间这个线程也没了,比较苦恼=。=

或者是否可以更新线程超时时间呢?每次心跳过来我都重新设置一个线程的超时时间

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
伊谢尔伦

Don’t use the idea of ​​fixed timeout.
There is a dedicated thread to manage all threads and receive heartbeats. This thread naturally has the heartbeat information of all threads. It also naturally knows which thread has not received heartbeats for more than 5 seconds, and then sends messages to the threads that should be terminated in this thread. interrupt signal.

左手右手慢动作

The simple way is to set the read timeout directly. The second is to use non-blocking IO to implement communication, so that the timeout program can be done directly in the current thread.

巴扎黑

Use netty for java communication, a choice you won’t regret

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template