What Is commons-io-2.11.jar

What Is commons-io-2.11.jar?

✍: FYIcenter.com

commons-io-2.11.jar is the JAR file for Commons IO 2.5, which is a library of utilities to assist with developing IO functionality.

JAR File Size and Download Location:

JAR name: commons-io-2.11.0.jar
Target JDK version: 8
Dependency: None

File name: commons-io.jar, commons-io-2.11.0.jar
File size: 327135 bytes
Release date: 01-22-2020
Download: Apache Commons IO Website

Java source code files for commons-io-2.11.jar are:

org/apache/commons/io/ThreadMonitor.java

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.io;

import java.time.Duration;

/**
 * Monitors a thread, interrupting it if it reaches the specified timeout.
 * <p>
 * This works by sleeping until the specified timeout amount and then
 * interrupting the thread being monitored. If the thread being monitored
 * completes its work before being interrupted, it should {@code interrupt()}
 * the <i>monitor</i> thread.
 * </p>
 *
 * <pre>
 *       long timeoutInMillis = 1000;
 *       try {
 *           Thread monitor = ThreadMonitor.start(timeoutInMillis);
 *           // do some work here
 *           ThreadMonitor.stop(monitor);
 *       } catch (InterruptedException e) {
 *           // timed amount was reached
 *       }
 * </pre>
 *
 */
class ThreadMonitor implements Runnable {

    private final Thread thread;
    private final Duration timeout;

    /**
     * Start monitoring the current thread.
     *
     * @param timeout The timeout amount in milliseconds
     * or no timeout if the value is zero or less
     * @return The monitor thread or {@code null}
     * if the timeout amount is not greater than zero
     */
    static Thread start(final Duration timeout) {
        return start(Thread.currentThread(), timeout);
    }

    /**
     * Start monitoring the specified thread.
     *
     * @param thread The thread The thread to monitor
     * @param timeout The timeout amount in milliseconds
     * or no timeout if the value is zero or less
     * @return The monitor thread or {@code null}
     * if the timeout amount is not greater than zero
     */
    static Thread start(final Thread thread, final Duration timeout) {
        if (timeout.isZero() || timeout.isNegative()) {
            return null;
        }
        final ThreadMonitor timout = new ThreadMonitor(thread, timeout);
        final Thread monitor = new Thread(timout, ThreadMonitor.class.getSimpleName());
        monitor.setDaemon(true);
        monitor.start();
        return monitor;
    }

    /**
     * Stop monitoring the specified thread.
     *
     * @param thread The monitor thread, may be {@code null}
     */
    static void stop(final Thread thread) {
        if (thread != null) {
            thread.interrupt();
        }
    }

    /**
     * Constructs a new monitor.
     *
     * @param thread The thread to monitor
     * @param timeout The timeout amount in milliseconds
     */
    private ThreadMonitor(final Thread thread, final Duration timeout) {
        this.thread = thread;
        this.timeout = timeout;
    }

    /**
     * Sleep until the specified timeout amount and then
     * interrupt the thread being monitored.
     *
     * @see Runnable#run()
     */
    @Override
    public void run() {
        try {
            sleep(timeout);
            thread.interrupt();
        } catch (final InterruptedException e) {
            // timeout not reached
        }
    }

    /**
     * Sleeps for a guaranteed minimum duration unless interrupted.
     *
     * This method exists because Thread.sleep(100) can sleep for 0, 70, 100 or 200ms or anything else
     * it deems appropriate. Read the docs on Thread.sleep for further interesting details.
     *
     * @param duration the sleep duration.
     * @throws InterruptedException if interrupted
     */
    private static void sleep(final Duration duration) throws InterruptedException {
        // Ignore nanos for now.
        final long millis = duration.toMillis();
        final long finishAtMillis = System.currentTimeMillis() + millis;
        long remainingMillis = millis;
        do {
            Thread.sleep(remainingMillis);
            remainingMillis = finishAtMillis - System.currentTimeMillis();
        } while (remainingMillis > 0);
    }


}

org/apache/commons/io/ThreadMonitor.java

 

Or download all of them as a single archive file:

File name: commons-io-2.11.0-sources.jar
File size: 398939 bytes
Release date: 2020-01-22
Download 

 

Download and Install commons-io-2.6-bin.zip

What Is commons-io-2.11-bin.zip

Download and Reviewing commons-io.jar

⇑⇑ FAQ for Apache commons-io.jar

2022-11-10, 81264👍, 2💬