简体   繁体   English

如何将ArrayList操作与Java线程并行化?

[英]How to parallelize ArrayList operations with Java Threads?

I have the Array list of passwords. 我有密码的数组列表。 And I want to check if file decrypts with that password. 我想检查文件是否使用该密码解密。 I want to use threads for applying the string transformations like adding the number to the end of the string. 我想使用线程来应用字符串转换,例如将数字添加到字符串的末尾。 What is the best way to do this using java threads or threadpool? 使用Java线程或线程池执行此操作的最佳方法是什么?

for (String pass : passwordDictionary) {
               setPassword(password);
               decrypt(secret)
               setPassword(password+numbers);
               decrypt(secret)

One of the possible ways is to use Stream.parallel() : 一种可能的方法是使用Stream.parallel()

passwordDictionary.stream().parallel().forEach(password -> { 
               setPassword(password);
               decrypt(secret)
               setPassword(password+numbers);
               decrypt(secret)
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM