稳定性升级

This commit is contained in:
Administrator
2023-07-26 21:30:00 +08:00
parent 585b7c5fe6
commit 722ab9710f
30 changed files with 720 additions and 158 deletions
@@ -0,0 +1,28 @@
package org.kne.cloud.network.klalb;
import java.util.concurrent.ConcurrentLinkedQueue;
public class ByteArrayRecycle {
private ConcurrentLinkedQueue<byte[]>rec=new ConcurrentLinkedQueue<>();
private int capacity;
private int length;
public ByteArrayRecycle(int capacity, int length) {
super();
this.capacity = capacity;
this.length = length;
}
public synchronized void recycle(byte[]b) {
if(b.length!=length)
throw new IllegalArgumentException("wrong length");
if(rec.size()<capacity) {
rec.add(b);
}
}
public synchronized byte[] create() {
byte[]b=rec.poll();
if(b==null) {
b=new byte[length];
}
return b;
}
}