Example usage for java.lang Runnable toString

List of usage examples for java.lang Runnable toString

Introduction

In this page you can find the example usage for java.lang Runnable toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:fi.jumi.core.suite.InternalErrorReportingExecutorTest.java

@Test
public void the_toString_of_the_original_commands_should_not_be_hidden() {
    SpyExecutor backingExecutor = new SpyExecutor();
    InternalErrorReportingExecutor executor = new InternalErrorReportingExecutor(backingExecutor, suiteListener,
            new PrintStream(new NullOutputStream()));
    Runnable originalCommand = () -> {
    };/*w ww .  j  ava  2 s .c  om*/

    executor.execute(originalCommand);

    assertThat(backingExecutor.lastCommand.toString(), containsString(originalCommand.toString()));
}

From source file:io.tilt.minka.spectator.Locks.java

private boolean createLock(final String lockName, final Runnable runnable, final boolean lockExclusively,
        final long lockWait, final TimeUnit lockWaitTimeUnit) {

    Validate.notNull(lockName, "the duty Name is required");
    Validate.notNull(runnable, "the duty Listener is required");

    boolean run = false;
    final CuratorFramework client = getClient();
    if (client == null) {
        logger.error("{}: ({}) Cannot use Distributed utilities before setting Zookeeper connection",
                getClass().getSimpleName(), getLogId());
        return false;
    }// w  w w .java  2 s.c  o m

    if (checkExistance(LOCK_PREFIX + lockName, runnable)) {
        throw new RuntimeException("Cannot create lock with existing name: " + lockName
                + " and the same listener! : " + runnable.toString());
    }

    InterProcessMutex mutex = null;
    final UserInstanceObject uo = new UserInstanceObject(mutex, runnable);

    final String lockNameObj = LOCK_PREFIX + lockName;
    try {
        add(lockNameObj, uo);
        mutex = new InterProcessMutex(client, lockNameObj);
        if (lockExclusively) {
            // i.e.: if other process has the lock: EXIT FAST
            if (run = mutex.acquire(lockWait, lockWaitTimeUnit)) {
                runnable.run();
            } else {
            }
        } else {
            mutex.acquire(); // wait until others release
            runnable.run();
            run = true;
        }
    } catch (Exception e) {
        if (isStarted() && isConnected()) {
            logger.error("{}: ({}) Unexpected while registering leader listener: {}",
                    getClass().getSimpleName(), getLogId(), lockNameObj, e);
        } else {
            logger.error("{}: ({}) Zookeper Disconnection: while registering leader listener: {}",
                    getClass().getSimpleName(), getLogId(), lockNameObj, e.getMessage());
        }
    } finally {
        try {
            if (mutex != null && mutex.isAcquiredInThisProcess()) {
                mutex.release();
            }
            remove(lockNameObj, uo);
            // just for consistency
            //runnable.stop();
        } catch (Exception e) {
            if (isStarted() && isConnected()) {
                logger.error("{}: ({}) Unexpected while releasing mutex: {}", getClass().getSimpleName(),
                        getLogId(), lockNameObj, e);
            } else {
                logger.error("{}: ({}) Zookeper Disconnection: while releasing mutex: {}",
                        getClass().getSimpleName(), getLogId(), lockNameObj, e.getMessage());
            }
        }
    }
    return run;
}

From source file:com.lizardtech.expresszip.vaadin.ExportOptionsViewComponent.java

@Override
public void taskQueued(Runnable r) {
    ((ExpressZipWindow) getApplication().getMainWindow())
            .showNotification(String.format("Job \"%s\" Queued", r.toString()));
}

From source file:be.solidx.hot.test.TestScriptExecutors.java

@SuppressWarnings("rawtypes")
private Collection<Long> multiThreadedTest(final Script script, final int max,
        final ScriptExecutor scriptExecutor) throws InterruptedException {
    final int iterations = 100;
    ExecutorService executor = Executors.newFixedThreadPool(8);
    final ConcurrentHashMap<String, Long> results = new ConcurrentHashMap<String, Long>();
    final ConcurrentHashMap<String, Long> avgs = new ConcurrentHashMap<String, Long>();
    long benchStart = System.currentTimeMillis();
    for (int i = 0; i < iterations; i++) {
        Runnable runnable = new Runnable() {
            @SuppressWarnings("unchecked")
            @Override//from  www .  j a va 2  s . c om
            public void run() {
                try {
                    long res = 0;
                    Map<String, Object> parameters = new HashMap<String, Object>();
                    parameters.put("i", new Integer(max));
                    parameters.put("n", new Integer(0));

                    //long starting = System.currentTimeMillis();
                    Object object = scriptExecutor.execute(script, parameters);
                    if (object instanceof Bindings) {
                        Bindings bindings = (Bindings) object;
                        res = (Integer) bindings.get("result");
                        bindings.clear();
                    } else if (object instanceof Double) {
                        res = Math.round((Double) object);
                    } else if (object instanceof Long) {
                        res = (long) object;
                    } else
                        res = new Long((Integer) object);
                    long end = System.currentTimeMillis() - avgs.get(this.toString());
                    results.put(UUID.randomUUID().getLeastSignificantBits() + "", res);
                    avgs.put(this.toString(), end);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        avgs.put(runnable.toString(), System.currentTimeMillis());
        executor.submit(runnable);
    }

    while (results.size() < iterations) {
        Thread.sleep(50);
    }
    //Thread.sleep(20000);
    double sum = 0;
    for (Long value : avgs.values()) {
        sum += value;
    }
    System.out.println((sum / (double) iterations) + "");
    System.out.println("==== Time needed for all requests: " + (System.currentTimeMillis() - benchStart));
    results.remove("avg");
    executor = null;
    return results.values();
}

From source file:org.apache.cocoon.thread.impl.DefaultThreadPool.java

/**
 * Execute a command// w w w  .ja  v a  2  s. c o  m
 *
 * @param command
 *                The {@link Runnable} to execute
 *
 * @throws InterruptedException
 *                 In case of interruption
 */
public void execute(Runnable command) throws InterruptedException {
    if (logger.isDebugEnabled()) {
        logger.debug("Executing Command: " + command.toString() + ",pool=" + getName());
    }

    super.execute(command);
}

From source file:org.epics.archiverappliance.config.DefaultConfigService.java

private void runShutDownHooksAndCleanup() {
    LinkedList<Runnable> shutDnHooks = new LinkedList<Runnable>(this.shutdownHooks);
    Collections.reverse(shutDnHooks);
    logger.debug("Running shutdown hooks in webapp " + this.warFile);
    for (Runnable shutdownHook : shutDnHooks) {
        try {//from  w  w  w  .j  ava  2 s  . c  o  m
            shutdownHook.run();
        } catch (Throwable t) {
            logger.warn("Exception shutting down service using shutdown hook " + shutdownHook.toString(), t);
        }
    }
    logger.debug("Done running shutdown hooks in webapp " + this.warFile);
}

From source file:org.mule.service.scheduler.internal.executor.ByCallerThreadGroupPolicy.java

@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
    ThreadGroup targetGroup = ((SchedulerThreadFactory) executor.getThreadFactory()).getGroup();
    ThreadGroup currentThreadGroup = currentThread().getThreadGroup();

    ++rejectedCount;//from w w  w  .  j a v a2 s.  co  m

    if ((isRunCpuLightWhenTargetBusyThread(currentThreadGroup) && targetGroup == couLightGroup)
            || (isWaitGroupThread(targetGroup) && targetGroup == currentThreadGroup)) {
        if (isLogRejectionEnabled()) {
            logRejection(r.toString(), callerRuns.getClass().getSimpleName(), targetGroup.getName());
        }
        callerRuns.rejectedExecution(r, executor);
    } else if (!isSchedulerThread(currentThreadGroup) || isWaitGroupThread(currentThreadGroup)) {
        if (isLogRejectionEnabled()) {
            logRejection(r.toString(), wait.getClass().getSimpleName(), targetGroup.getName());
        }
        // MULE-11460 Make CPU-intensive pool a ForkJoinPool - keep the parallelism when waiting.
        wait.rejectedExecution(r, executor);
    } else {
        if (isLogRejectionEnabled()) {
            logRejection(r.toString(), abort.getClass().getSimpleName(), targetGroup.getName());
        }
        abort.rejectedExecution(r, executor);
    }
}

From source file:org.openhab.binding.zoneminder.handler.ZoneMinderServerBridgeHandler.java

/**
 * Method to start a data refresh task./*from   w  w w . j a va2s .co m*/
 */
protected ScheduledFuture<?> startTask(Runnable command, long delay, long interval, TimeUnit unit) {
    logger.debug("BRIDGE [{}]: Starting ZoneMinder Bridge Monitor Task. Command='{}'", getThingId(),
            command.toString());
    if (interval == 0) {
        return null;
    }

    return scheduler.scheduleWithFixedDelay(command, delay, interval, unit);
}