Example usage for java.lang Thread equals

List of usage examples for java.lang Thread equals

Introduction

In this page you can find the example usage for java.lang Thread equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.mgmtp.jfunk.core.scripting.ModuleArchiver.java

private void addModuleAppender() {
    final Thread thread = Thread.currentThread();

    moduleAppender = new FileAppender<ILoggingEvent>() {
        @Override//from  ww  w  . j a va  2  s.  c  om
        protected void subAppend(final ILoggingEvent event) {
            if (thread.equals(Thread.currentThread())) {
                super.subAppend(event);
            }
        }
    };

    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    moduleAppender.setContext(loggerContext);
    moduleAppender.setFile(new File(moduleArchiveDir, "module.log").getPath());

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(loggerContext);
    encoder.setPattern("%date{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg%n");
    encoder.start();

    moduleAppender.setEncoder(encoder);
    moduleAppender.start();

    // attach the rolling file appender to the logger of your choice
    ch.qos.logback.classic.Logger logbackLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    logbackLogger.addAppender(moduleAppender);
}

From source file:de.ks.flatadocdb.session.Session.java

public void checkCorrectThread() {
    Thread currentThread = Thread.currentThread();
    if (!currentThread.equals(this.thread)) {
        throw new IllegalSessionThreadException(
                "Trying to use session in thread " + currentThread + " but can only be used in " + thread);
    }/*from w  w  w  .  j a  va2 s  . c o m*/
}

From source file:de.innovationgate.wgpublisher.webtml.utils.TMLContext.java

@CodeCompletion
public void waitforauthupdates(WGDatabase db, int timeoutSeconds) throws WGAServerException {

    if (db == null) {
        db = db();/*ww  w. j a v a  2s .c o  m*/
    }

    // Collect the CSAuthModules listening to content save events on this database
    List listeners = db.getContentEventListeners();
    List modules = new ArrayList();
    synchronized (listeners) {
        Iterator it = listeners.iterator();
        while (it.hasNext()) {
            WGContentEventListener listener = (WGContentEventListener) it.next();
            if (listener instanceof CSAuthModule) {
                modules.add(listener);
            }
        }
    }

    // Look thru the modules until their currently running update threads have finished
    long timeout = System.currentTimeMillis() + (timeoutSeconds * 1000);
    Map moduleThreads = new HashMap();
    do {

        // Idle. Check timeout
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        if (System.currentTimeMillis() > timeout) {
            throw new WGAServerException(
                    "Method waitForAuthUpdates() encountered timout of " + timeoutSeconds + "seconds");
        }

        // Iterate modules
        Iterator modIt = modules.iterator();
        while (modIt.hasNext()) {
            CSAuthModule mod = (CSAuthModule) modIt.next();

            // Look if a collector runs right now. If not, then this module is thru
            if (mod.getCurrentCollectorThread() == null) {
                modIt.remove();
            }

            // A collection runs right now.
            else {

                // Retrieve an maybe recorded earlier thread
                Thread earlierThread = (Thread) moduleThreads.get(mod);

                // if there is no earlier thread then we just haven't recorded it yet
                if (earlierThread == null) {
                    moduleThreads.put(mod, mod.getCurrentCollectorThread());
                }

                // If there was an earlier thread, we look if it is still the same. If not, the earlier thread is finished and our update most likely thru
                else if (!earlierThread.equals(mod.getCurrentCollectorThread())) {
                    modIt.remove();
                }

            }
        }

    } while (modules.size() > 0);

}

From source file:org.mule.DefaultMuleMessage.java

private void checkMutable(boolean write) {

    // IF YOU SEE AN EXCEPTION THAT IS RAISED FROM WITHIN THIS CODE
    // ============================================================
    ////w ww.  jav a 2  s.  c  om
    // First, understand that the exception here is not the "real" problem.  These exceptions
    // give early warning of a much more serious issue that results in unreliable and unpredictable
    // code - more than one thread is attempting to change the contents of a message.
    //
    // Having said that, you can disable these exceptions by defining
    // MuleProperties.MULE_THREAD_UNSAFE_MESSAGES_PROPERTY (mule.disable.threadsafemessages)
    // (i.e., by adding -Dmule.disable.threadsafemessages=true to the java command line).
    //
    // To remove the underlying cause, however, you probably need to do one of:
    //
    // - make sure that the message you are using correctly implements the ThreadSafeAccess
    //   interface
    //
    // - make sure that dispatcher and receiver classes copy ThreadSafeAccess instances when
    //   they are passed between threads

    Thread currentThread = Thread.currentThread();
    if (currentThread.equals(ownerThread.get())) {
        if (write && !mutable.get()) {
            if (isDisabled()) {
                logger.warn("Writing to immutable message (exception disabled)");
            } else {
                throw newException("Cannot write to immutable message");
            }
        }
    } else {
        if (write) {
            if (isDisabled()) {
                logger.warn("Non-owner writing to message (exception disabled)");
            } else {
                throw newException("Only owner thread can write to message: " + ownerThread.get() + "/"
                        + Thread.currentThread());
            }
        }
    }
}

From source file:org.mule.MuleWorkManagerTestCase.java

@Test
public void testScheduleWorkExecutesAsynchronously() throws Exception {
    final Thread callerThread = Thread.currentThread();

    MuleWorkManager wm = new MuleWorkManager(ThreadingProfile.DEFAULT_THREADING_PROFILE, null, 5000);
    wm.setMuleContext(muleContext);/*from w  ww.j  a  v  a 2s  . c o  m*/

    try {
        wm.start();

        wm.scheduleWork(new Work() {
            public void release() {
                // no-op
            }

            public void run() {
                Thread calleeThread = Thread.currentThread();
                assertFalse("WorkManager.scheduleWork() should have been executed in a different thread.",
                        callerThread.equals(calleeThread));
                if (logger.isDebugEnabled()) {
                    logger.debug("WORK: " + Thread.currentThread());
                }
            }
        });
        if (logger.isDebugEnabled()) {
            logger.debug("MAIN: " + Thread.currentThread());
        }
    } finally {
        wm.dispose();
    }

}

From source file:org.mule.MuleWorkManagerTestCase.java

@Test
public void testStartWorkExecutesAsynchronously() throws Exception {
    final Thread callerThread = Thread.currentThread();

    MuleWorkManager wm = new MuleWorkManager(ThreadingProfile.DEFAULT_THREADING_PROFILE, null, 5000);
    wm.setMuleContext(muleContext);/*  w ww  . ja v  a  2 s.  c  om*/

    try {
        wm.start();

        wm.startWork(new Work() {
            public void release() {
                // no-op
            }

            public void run() {
                Thread calleeThread = Thread.currentThread();
                assertFalse("WorkManager.startWork() should have been executed in a different thread.",
                        callerThread.equals(calleeThread));
                if (logger.isDebugEnabled()) {
                    logger.debug("WORK: " + Thread.currentThread());
                }
            }
        });
        if (logger.isDebugEnabled()) {
            logger.debug("MAIN: " + Thread.currentThread());
        }
    } finally {
        wm.dispose();
    }

}