private Job prepareJob(String name, Runnable runnable, Schedule when) {
		// lock needed to make sure 2 jobs with the same name are not submitted at the same time
		synchronized (indexedJobsByName) {
			Job lastJob = findJob(name).orElse(null);

			if(lastJob != null && lastJob.status() != JobStatus.DONE) {
				throw new IllegalArgumentException("A job is already scheduled with the name:" + name);
			}

			Job job = new Job(
				JobStatus.DONE,
				0L,
				lastJob != null ? lastJob.executionsCount() : 0,
				lastJob != null ? lastJob.lastExecutionStartedTimeInMillis() : null,
				lastJob != null ? lastJob.lastExecutionEndedTimeInMillis() : null,
				name,
				when,
				runnable
			);
			indexedJobsByName.put(name, job);

			return job;
		}
	}
private Job prepareJob ( String name , Runnable runnable , Schedule when ) { synchronized ( indexedJobsByName ) { Job lastJob = findJob ( name ) . orElse ( null ) ; if ( lastJob != null && lastJob . status ( ) != JobStatus . DONE ) { throw new IllegalArgumentException ( "A job is already scheduled with the name:" + name ) ; } Job job = new Job ( JobStatus . DONE , 0L , lastJob != null ? lastJob . executionsCount ( ) : 0 , lastJob != null ? lastJob . lastExecutionStartedTimeInMillis ( ) : null , lastJob != null ? lastJob . lastExecutionEndedTimeInMillis ( ) : null , name , when , runnable ) ; indexedJobsByName . put ( name , job ) ; return job ; } }
internal