类org.apache.commons.lang3.concurrent.TimedSemaphore源码实例Demo

下面列出了怎么用org.apache.commons.lang3.concurrent.TimedSemaphore的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ReplicaDB   文件: SqlManager.java
/**
 * Create a bandwith cap, estimating the size of the first row returned by the resultset
 * and using it as permits in the rate limit.
 *
 * @param resultSet the resultset cursor moved to the first row (resultSet.next())
 * @param rsmd      the result set metadata object
 * @throws SQLException
 */
protected void bandwidthThrottlingCreate(ResultSet resultSet, ResultSetMetaData rsmd) throws SQLException {
    int kilobytesPerSecond = options.getBandwidthThrottling();

    if (kilobytesPerSecond > 0) {
        // Stimate the Row Size
        for (int i = 1; i <= rsmd.getColumnCount(); i++) {

            if (rsmd.getColumnType(i) != Types.BLOB) {
                String columnValue = resultSet.getString(i);
                if (columnValue != null && !resultSet.getString(i).isEmpty())
                    rowSize = rowSize + resultSet.getString(i).length();
            }
        }

        double limit = ((1.0 * kilobytesPerSecond) / rowSize) / (options.getFetchSize() * 1.0 / 1000);
        if (limit == 0) limit = 1;
        this.bandwidthRateLimiter = new TimedSemaphore(1, TimeUnit.SECONDS, (int) Math.round(limit));

        LOG.info("Estimated Row Size: {} KB. Estimated limit of fetchs per second: {} ", rowSize, limit);


    }
}
 
源代码2 项目: cyberduck   文件: LimitedRendezvousListener.java
public LimitedRendezvousListener(final Set<RendezvousListener> listeners) {
    this(new TimedSemaphore(
            1L, TimeUnit.MINUTES, PreferencesFactory.get().getInteger("rendezvous.notification.limit")), listeners);
}
 
源代码3 项目: cyberduck   文件: LimitedRendezvousListener.java
public LimitedRendezvousListener(final TimedSemaphore limit, final Set<RendezvousListener> listeners) {
    this.limit = limit;
    this.listeners = listeners;
}
 
源代码4 项目: tutorials   文件: DelayQueueUsingTimedSemaphore.java
DelayQueueUsingTimedSemaphore(long period, int slotLimit) {
    semaphore = new TimedSemaphore(period, TimeUnit.SECONDS, slotLimit);
}
 
 类所在包
 类方法
 同包方法