fix: mes对接
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package org.nl.ext;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description:
|
||||
* @Date: 2023/9/18
|
||||
*/
|
||||
public class StorageManager {
|
||||
private int requestCount = 0;
|
||||
|
||||
public String allocateStorage() {
|
||||
requestCount++;
|
||||
if (requestCount >= 1 && requestCount <= 5) {
|
||||
return "上货位";
|
||||
} else if (requestCount >= 6 && requestCount <= 10) {
|
||||
return "下货位";
|
||||
} else {
|
||||
// 如果请求次数大于10,循环上下
|
||||
requestCount = 1;
|
||||
return "上货位";
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
StorageManager manager = new StorageManager();
|
||||
|
||||
// 模拟外部系统的请求
|
||||
for (int i = 1; i <= 23; i++) {
|
||||
new Thread(() -> {
|
||||
String storage = manager.allocateStorage();
|
||||
System.out.println("第 " + Thread.currentThread().getName() + " 次请求,分配到:" + storage);
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,20 +29,25 @@ public class TestDemo {
|
||||
@Test
|
||||
public void test01() {
|
||||
for (int i = 0; i < 13; i++) {
|
||||
toAdd();
|
||||
int up = countUp.get();
|
||||
int lower = countLower.get();
|
||||
if (lower == 0 || lower != 5) {
|
||||
countLower.incrementAndGet();
|
||||
} else {
|
||||
countUp.incrementAndGet();
|
||||
}
|
||||
if (up == 4) {
|
||||
countLower = new AtomicInteger(0);
|
||||
}
|
||||
if (lower == 4 && up == 4) {
|
||||
countUp = new AtomicInteger(0);
|
||||
}
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toAdd();
|
||||
int up = countUp.get();
|
||||
int lower = countLower.get();
|
||||
if (lower == 0 || lower != 5) {
|
||||
countLower.incrementAndGet();
|
||||
} else {
|
||||
countUp.incrementAndGet();
|
||||
}
|
||||
if (up == 4) {
|
||||
countLower = new AtomicInteger(0);
|
||||
}
|
||||
if (lower == 4 && up == 4) {
|
||||
countUp = new AtomicInteger(0);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +55,7 @@ public class TestDemo {
|
||||
int up = countUp.get();
|
||||
int lower = countLower.get();
|
||||
boolean isASC = false;
|
||||
if (lower == 0 || lower != 5) {
|
||||
if (lower < 5) {
|
||||
isASC = true;
|
||||
}
|
||||
if (isASC) {
|
||||
|
||||
Reference in New Issue
Block a user