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

com.firefly.utils.concurrent.SynchronousObject Maven / Gradle / Ivy

There is a newer version: 4.0.3.2
Show newest version
package com.firefly.utils.concurrent;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

import com.firefly.utils.log.Log;
import com.firefly.utils.log.LogFactory;

public class SynchronousObject {
	private static Log log = LogFactory.getInstance().getLog("firefly-system");
	private SynchronousQueue queue = new SynchronousQueue();
	
	public void put(T obj, long timeout) {
		try {
			queue.offer(obj, timeout, TimeUnit.MILLISECONDS);
		} catch (InterruptedException e) {
			log.error("put synchronous obj error", e);
		}
	}
	
	public T get(long timeout) {
		T t = null;
		try {
			t = queue.poll(timeout, TimeUnit.MILLISECONDS);
		} catch (InterruptedException e) {
			log.error("get synchronous obj error", e);
		}
		return t;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy