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

org.jcodec.common.io.AutoPool Maven / Gradle / Ivy

There is a newer version: 0.2.5
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy