if i were you i do it like this using multi-threading.

1- Thread1: reading image and resizing them then adding them into the queue
2- Thread2: deguing images from the queue and adding them to the hashmap
3- Thread Safty: i implement Mutex objet for locking on queue or Semaphore if i needed somehow more than one thread enter the critical section of my code.