我正在尝试创建 100k 以太坊钱包用于测试目的。所有人都应该使用相同的密码短语,因为现在没关系。我用 10 个线程启动了这段代码,它冻结了我的 macbook,我不得不重新启动它。3 线程有点工作,但它仍然很慢(每秒生成约 6 个钱包)。怎么了?我正在使用web3j依赖项
public EthWallets(String[] args)
{
File destinationDir = new File("ethwallets/");
if(args[1].equalsIgnoreCase("create")) {
try {
int count = Integer.valueOf(args[2]);
if(count > 10)
{
final int threadedCount = count / 10;
for(int i = 0; i < 10; i++)
{
Thread t = new Thread()
{
@Override
public void run() {
for(int j = 0; j < threadedCount; j++)
{
create("passphph", destinationDir);
}
}
};
t.start();
}
}
else
for(int i = 0; i < count; i++)
create("passphph", destinationDir);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void create(String passPhrase, File destinationDirectory)
{
try {
String path = WalletUtils.generateFullNewWalletFile(passPhrase, destinationDirectory);
// Credentials credentials = WalletUtils.loadCredentials(passPhrase, new File(path));
// System.out.println("address: " + credentials.getAddress());
// System.out.println("private: " + credentials.getEcKeyPair().getPrivateKey());
// System.out.println("public: " + credentials.getEcKeyPair().getPublicKey());
} catch (Exception e) {
e.printStackTrace();
}
}