Made the java code run on a separate thread.