我正在尝试模拟(仅模拟!!)退避算法,我不知道我是不是正确的路径?
无论如何,它是这样的:
那么我可以使用分布式系统(套接字TCP / UDP)实现这种情况吗?还是使用多线程?
/**
* canal is global variable . if 0 means can the thread can do the
* retransmission else if its 1 then no thread can do retransmission
*/
public int canal = 0;
/**
* Each thread got timeSlot that can take random value between two numbers 1 and 12 .
* timeSlot value start decreasing until 0.
*/
public void backOff() {
int timeSlot = 1 + (int) (Math.random() * ((12 - 1) + 1));
for (int i = timeSlot; i <= 0; i--) {
timeSlot--;
System.out.println("timeSlot number :" + timeSlot);
}
if (canal == 0) {
canal = 1;
System.out.println("retransmission)");
canal = 0;
}
}