asmack reconnection启动两次

本文详细介绍了如何优化Smack框架中重连线程的实现,通过引入随机等待时间来避免重复启动重连线程的问题,并在代码中实现了这一改进。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

 

原文出处:http://issues.igniterealtime.org/browse/SMACK-325

 

# This patch file was generated by NetBeans IDE

# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.

# It uses platform neutral UTF-8 encoding.

# Above lines and this line are ignored by the patching process.

3d2

< import java.util.Random;

24,25d22

< private Thread reconnectionThread;

< private int randomBase = new Random().nextInt(11) + 5; // between 5 and 15 seconds

68c65

<     synchronized protected void reconnect() {

---

>     protected void reconnect() {

70,72d66

<             // avoid to run duplicated reconnectionThread -- fd: 16/09/2010

<             if (reconnectionThread!=null && reconnectionThread.isAlive()) return;

<

75c69

< reconnectionThread = new Thread() {

---

>             Thread reconnectionThread = new Thread() {

87d80

< // fd: 16/09/10; modified to add a random wait

89d81

< attempts++;

91c83

<                         return randomBase*6*5;      // between 2.5 and 7.5 minutes (~5 minutes)

---

>                         return 60 * 5;      // 5 minutes

94c86

<                         return randomBase*6;       // between 30 and 90 seconds (~1 minute)

---

>                         return 60;          // 1 minute

96,98c88

<                     return randomBase;              // between 5 and 15 seconds (~10 seconds)

---

>                     return 10;              // 10 seconds

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

linyu19872008

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值