Java exercise with concurrency