您当前的位置: 首页 >  Java

石头wang

暂无认证

  • 1浏览

    0关注

    295博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

shell或bat脚本是不是顺序执行,是多线程吗,会不等待java执行结果吗

石头wang 发布时间:2021-10-23 10:55:27 ,浏览量:1

背景

研究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秒,根本就不可能触发限流。

关注
打赏
1663722529
查看更多评论
立即登录/注册

微信扫码登录

0.1241s