Generating Ethereum wallets with 10 threads in Java freezes computer

281 views Asked by At

I'm trying to create 100k ethereum wallets for test purposes. All should use same pass phrase, because it doesn't matter right now. I launched this code with 10 threads and it froze my macbook, I had to restart it. 3 thread somewhat work, but it's still very slow (generates like ~6 wallets a second). What's wrong? I'm using web3j dependency

    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();
        }
    }
1

There are 1 answers

0
MrGoodKat On

I suggest you to read this reply from https://stackoverflow.com/a/1718522/5632150

As he said, the number of threads you can spawn depends on the fact that your threads do or do not any I/O operation. If so there are some ways to optimize this problem. If not I usually do MAX_THREADS = N_CORES + 1.