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

io.baltoro.remote.WorkerPool Maven / Gradle / Ivy

There is a newer version: 4.0.12
Show newest version
package io.baltoro.remote;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;

public class WorkerPool
{

	private static ConcurrentLinkedQueue free = new ConcurrentLinkedQueue<>();
	private static Set busy = new HashSet<>();
	
	static RequestWorker get()
	{
		if(free.size() == 0)
		{
			return null;
		}
		
		
		RequestWorker worker = free.poll();
		busy.add(worker);
		return worker;
	}
	
	static void done(RequestWorker worker)
	{
		worker.clear();
		busy.remove(worker);
		free.add(worker);
	}
	

	static String info()
	{
		return "free : "+free.size()+" busy : "+busy.toArray().length;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy