Java Examples for net.jcip.annotations.ThreadSafe

The following java examples will help you to understand the usage of net.jcip.annotations.ThreadSafe. These source code samples are taken from different open source projects.

Example 1
Project: libreveris-master  File: RunsTableFactory.java View source code
//--------------//
// isThreadSafe //
//--------------//
/**
         * The concurrency aspects of the adapter depends on the
         * underlying PixelFilter.
         *
         * @return true if safe, false otherwise
         */
@Override
public boolean isThreadSafe() {
    Class<?> classe = source.getClass();
    // Check for @ThreadSafe annotation
    ThreadSafe safe = classe.getAnnotation(ThreadSafe.class);
    if (safe != null) {
        return true;
    }
    // Check for @NonThreadSafe annotation
    NotThreadSafe notSafe = classe.getAnnotation(NotThreadSafe.class);
    if (notSafe != null) {
        return false;
    }
    // No annotation: it's safer to assume no thread safety
    return false;
}
Example 2
Project: s4-piper-master  File: ProcessingElement.java View source code
/* This method is called by App just before the application starts. */
void initPEPrototypeInternal() {
    /* Eagerly create singleton PE. */
    if (isSingleton) {
        try {
            peInstances.get(SINGLETON);
            logger.trace("Created singleton [{}].", getInstanceForKey(SINGLETON));
        } catch (ExecutionException e) {
            logger.error("Problem when trying to create a PE instance.", e);
        }
    }
    /* Start timer. */
    if (timer != null) {
        timer.schedule(new OnTimeTask(), 0, timerIntervalInMilliseconds);
        logger.info("Started timer for PE [{}] with ID [{}].", this.getClass().getName(), id);
    }
    /* Check if this PE is annotated as thread safe. */
    if (getClass().isAnnotationPresent(ThreadSafe.class) == true) {
        // TODO: this doesn't seem to be working. isannotationpresent always returns false.
        isThreadSafe = true;
        logger.trace("Annotated with @ThreadSafe");
    }
}
Example 3
Project: incubator-s4-master  File: ProcessingElement.java View source code
/* This method is called by App just before the application starts. */
protected void initPEPrototypeInternal() {
    /* Eagerly create singleton PE. */
    if (isSingleton) {
        try {
            peInstances.get(SINGLETON);
            logger.trace("Created singleton [{}].", getInstanceForKey(SINGLETON));
        } catch (ExecutionException e) {
            logger.error("Problem when trying to create a PE instance.", e);
        }
    }
    /* Start timer. */
    if (triggerTimer != null) {
        triggerTimer.scheduleAtFixedRate(new OnTimeTask(), 0, timerIntervalInMilliseconds, TimeUnit.MILLISECONDS);
        logger.debug("Started timer for PE prototype [{}], ID [{}] with interval [{}].", new String[] { this.getClass().getName(), id, String.valueOf(timerIntervalInMilliseconds) });
    }
    if (checkpointingConfig.mode == CheckpointingMode.TIME) {
        ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).setUncaughtExceptionHandler(new UncaughtExceptionHandler() {

            @Override
            public void uncaughtException(Thread t, Throwable e) {
                logger.error("Expection from checkpointing thread", e);
            }
        }).setNameFormat("Checkpointing-trigger-" + getClass().getSimpleName()).build();
        checkpointingTimer = Executors.newSingleThreadScheduledExecutor(threadFactory);
        checkpointingTimer.scheduleAtFixedRate(new CheckpointingTask(this), checkpointingConfig.frequency, checkpointingConfig.frequency, checkpointingConfig.timeUnit);
        logger.debug("Started checkpointing timer for PE prototype [{}], ID [{}] with interval [{}] [{}].", new String[] { this.getClass().getName(), id, String.valueOf(checkpointingConfig.frequency), String.valueOf(checkpointingConfig.timeUnit.toString()) });
    }
    /* Check if this PE is annotated as thread safe. */
    if (getClass().isAnnotationPresent(ThreadSafe.class) == true) {
        // TODO: this doesn't seem to be working. isannotationpresent always returns false.
        isThreadSafe = true;
        logger.trace("Annotated with @ThreadSafe");
    }
}