org.jcodec.common.io.AutoPool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jcodec Show documentation
Show all versions of jcodec Show documentation
Pure Java implementation of video/audio codecs and formats
package org.jcodec.common.io;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* This class is part of JCodec ( www.jcodec.org )
* This software is distributed under FreeBSD License
*
* @author The JCodec project
*
*/
public class AutoPool {
private static AutoPool instance = new AutoPool();
private List resources = Collections.synchronizedList(new ArrayList());
private ScheduledExecutorService scheduler;
private AutoPool() {
scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
long curTime = System.currentTimeMillis();
List res = resources;
for (AutoResource autoResource : res) {
autoResource.setCurTime(curTime);
}
}
}, 0, 100, TimeUnit.MILLISECONDS);
}
public static AutoPool getInstance() {
return instance;
}
public void add(AutoResource res) {
resources.add(res);
}
}