Why does my Thread (Runnable) not get off the run() method once it reaches end of the block?
This is the code:
//1 Entry point for thread with run method
public void run() {
System.out.println("Hashmaker():/run(). " + threadName + " Running " );
try {
String original = in;
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(original.getBytes());
byte[] digest = md.digest();
StringBuffer sb = new StringBuffer();
for (byte b : digest) {
sb.append(String.format("%02x", b & 0xff));
System.out.println("Hashmaker:/run(). original: " + original);
System.out.println("Hashmaker:/run(). digested(hex):" + sb.toString());
//src http://www.avajava.com/tutorials/lessons/how-do-i-generate-an-md5-digest-for-a-string.html
}
// Let the thread sleep for a while.
//Thread.sleep(7);
System.out.println("Hashmaker:/run(). Thread: " + threadName + " recieved a clear password = " + in);
//Save the hash
hash=sb.toString();
}
/*catch (InterruptedException e) {
System.out.println("Hashmaker:/run(). Thread " + threadName + " interrupted.");
} */
catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Hashmaker:/run(). Thread " + threadName + " exiting.");
}
It is ideally supposed to end normally, then my main() method would start other stuff:
public static void main(String[] args) throws Exception {
//Parse the args
if (args.length != 1) {
System.err.println("Main()/: String to MD5 digest should be first parameter\n");
System.out.println("Main()/: Require now a clear password with 4 char :");
sc = new Scanner(System.in);
in = sc.nextLine();
force = 2;
}
else{
in = args[0];
force = Integer.parseInt(args[1]);
}
//Set the count of Breakers
count=force;
//Make the hash
Hashmaker hm = new Hashmaker(in,"Hashmaker");
hm.start();
System.out.println("Main()/: Managing the breakers will start !");
//Get the hash
hash=hm.getHash();
//Manage the Breakers
f = new File(count);
for(int i=0; i<count;i++){
Hashbreaker hb = new Hashbreaker(hash,"HashBreaker"+i);
f.enfiler(hb);
hb.start();
}
}
THE NORMAL SCENARIO TO ME, IS: create and start a thread to generate a digest MD5 hash, get the hash, feed consumer thread with it and bruteforce it till one bruteforce hash give a "compareTo" secret hash == 1.