如何在groovy中实现多线程?

How to implement multithreading in groovy?

我要创建1000万客户进行性能测试。我是 运行 一个基本的 groovy 脚本,用于创建仅具有强制属性的客户。那我就是运行循环里面的脚本了
如何提高此 groovy 脚本的性能?
在impex import中找不到相应的多线程选项。

有没有更好的方法在 Hybris 中创造 1000 万客户?

编辑 1:

用于生成具有不同 ID 的客户的示例 groovy 脚本。

    import com.google.common.collect.ImmutableSet
    import de.hybris.platform.core.model.user.AddressModel
    import de.hybris.platform.core.model.user.CustomerModel

    //Setting only mandatory attributes
    for(int i=0; i<100000; i++) {
        customerModel = new CustomerModel()
        id = new Random().nextInt(100000000)
        uid = 'TestCustomer_'+id
        customerModel.setUid(uid)
        name = 'Test Customer Name_'+id
        customerModel.setName(name)

        addressModel = new AddressModel()
        addressModel.setOwner(customerModel)
        customerModel.setDefaultPaymentAddress(addressModel)
        customerModel.setDefaultShipmentAddress(addressModel)

        try{
        modelService.save(customerModel)
        }catch(Exception e){
        println('Creation of customer with id = '+uid+' and amway account = '+code+' failed with error : '+e.getMessage())
        }
    }

我会说合乎逻辑的答案是使用 Impex 文件。这允许批量创建并支持多线程:https://help.hybris.com/1811/hcd/44f79c4e604a4bff8456a852e617d261.html

基本上你可以配置工人或线程的数量:

impex.import.workers=4

您将负责将输入格式转换为 *.csv 或 *.impex

补充: 关于Groovy脚本,可以用impex设置uid和name,只是需要提前提供随机数。您可以在 Excel 或某些脚本语言中执行此操作。

您甚至可以通过代码执行在 impex 中完成。

但如果您只是想要很多随机客户:您也可以使用 /hac 和 运行 脚本启动 10 个浏览器 windows 十次。

我用上面的 groovy 脚本 创建了多个 ScriptingJob,并将它们附加到 30 个不同的 Cronjobs。并行执行所有这些都取得了相同的结果。