All Downloads are FREE. Search and download functionalities are using the official Maven repository.

blah.concurrency.second.JobRunner Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package blah.concurrency.second;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class JobRunner implements Runnable {
	
	final JobQueue buffer;
	final JobDispatcher dispatcher;
	
	Job currentJob;

	@Override
	public void run() {
		while( true )
			if ( hasMoreJobsToRun() )
				tryRunCurrentJob();
	}

	void tryRunCurrentJob() {
		try {
			currentJob.run( dispatcher );
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	boolean hasMoreJobsToRun(){
		try {
			currentJob = buffer.get();
			return currentJob != null;
		} catch (InterruptedException e) {
			return false;
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy