Multithreaded string handling in java