Is there a way that you could keep track of how many incomplete tasks there are in the system? Like with a counter that you increment every time a taks is assigned, and decremement every time a task is completed? When the count reaches zero, you could just call System.exit(0). Of course, you'd have to make sure that check isn't made until
after you've started some tasks, or the system will exit before it begins.
There are of course other ways to track incomplete tasks. You might have a List of tasks which have not been completed, for example. Or perhaps two - one List of tasks which had not even been started yet, and another List of tasks which were being worked on by a thread. Once both lists have size() == 0, exit.