Execution of different tasks in java