背景
研究bat/sh脚本是否是多线程执行的(或者说对java的jar进行调用是否调用后就立即返回,还是需要等到执行完毕再执行下面的脚本)
动手实验Test.java类,代码如下
public class Test {
public static void main(String[] args) throws InterruptedException {
System.out.println("------- main enter ------------");
if (args == null || args.length == 0) {
throw new RuntimeException("Please input param (args[0],unit is second)");
}
int seconds = Integer.parseInt(args[0]);
for (int i = 1; i java -cp hello-bat-is-not-multi-thread-1.0-SNAPSHOT.jar com.wyf.test.Test 10
------- main enter ------------
---- sleeping: 1 / 10
---- sleeping: 2 / 10
---- sleeping: 3 / 10
---- sleeping: 4 / 10
---- sleeping: 5 / 10
---- sleeping: 6 / 10
---- sleeping: 7 / 10
---- sleeping: 8 / 10
---- sleeping: 9 / 10
---- sleeping: 10 / 10
------- main exit ------------
D:\DevFolder\code\hello\hello-bat-is-not-multi-thread\target>echo RunningScriptHere
RunningScriptHere
D:\DevFolder\code\hello\hello-bat-is-not-multi-thread\target>java -cp hello-bat-is-not-multi-thread-1.0-SNAPSHOT.jar com.wyf.test.Test 2
------- main enter ------------
---- sleeping: 1 / 2
---- sleeping: 2 / 2
------- main exit ------------
D:\DevFolder\code\hello\hello-bat-is-not-multi-thread\target>pause
请按任意键继续. . .
补充
上述的研究背景是什么?上述是为了研究接口的限流,配置了1秒内只能调用1次否则就触发限流,由于手速没这么快,想用脚本来替代(不想jmeter或者其他方式),然后就研究了这个,发现这种做法没办法满足,假设接口耗时超过1秒,根本就不可能触发限流。