I have exercise to learn multithread. I have one correct password like: xxYYmmDD xx is a initials from my "Employees" list, YY is a year of birth, mm is a month of birth and DD is a day of birth. For example: Nichole Hunter 09/10/93 password is: NH930910. But this loop know only about it a password start from initials and after that have 6 numbers. (later i have to create other loops with another method and compare which method with multithread is faster to find password but this is not important now)
I have loop which work in multithreads and for every single initial adding a String of number from 000000 to 999999 and checking it equals to correct password. I have no idea why instruction from "if" is never call. Some one know how to help? And how to stop other Threads if i find correct password?
executorService= Executors.newFixedThreadPool(30);
String finalCorrect = correct;
for(String x : inicials){
executorService.submit(()->{
for(int count=0;count<999999; count++){
if(finalCorrect.equals(x+String.format("%06d", count).trim())){
System.out.println("Correct password is: "+x+String.format("%06d", count).trim());
System.out.println("The really password is: "+ finalCorrect);
break;
}
}
}
);
}
executorService.shutdown();
try {
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException x) {
System.out.println(x);
}
Aucun commentaire:
Enregistrer un commentaire