public void runViewUpdate(final Runnable runnable, final boolean preserveExpansion) { if (Utils.canUpdateViewer(getViewer()) || isPerformingBackgroundUpdate()) { internalRunViewUpdate(runnable, preserveExpansion); } else { if (Thread.currentThread() != getEventHandlerJob().getThread()) { // Run view update should only be called from the UI thread or // the update handler thread. // We will log the problem for now and make it an assert later TeamUIPlugin.log( IStatus.WARNING, "View update invoked from invalid thread", new TeamException( "View update invoked from invalid thread")); //$NON-NLS-1$ //$NON-NLS-2$ } final Control ctrl = getViewer().getControl(); if (ctrl != null && !ctrl.isDisposed()) { ctrl.getDisplay() .syncExec( new Runnable() { public void run() { if (!ctrl.isDisposed()) { BusyIndicator.showWhile( ctrl.getDisplay(), new Runnable() { public void run() { internalRunViewUpdate(runnable, preserveExpansion); } }); } } }); } } }
/** @see java.lang.Thread#run() */ public void run() { // Wait for registration. Put it into a thread so this // can occur while other stuff goes on. It locks the fConnectionPool // until done so that the first request for a connection by anyone // else will wait until this thread is finished. synchronized (fConnectionPool) { synchronized (REMProxyFactoryRegistry.this) { // Notify the main thread that we have the // connection pool locked. REMProxyFactoryRegistry.this.notifyAll(); } synchronized (this) { // sync on self so that it can be notified when finally receive the registration long stopTime = System.currentTimeMillis() + 60000; while (waitRegistrationThread != null && (fNoTimeouts || System.currentTimeMillis() < stopTime)) { try { Thread.currentThread().wait(60000); } catch (InterruptedException e) { } } } } waitRegistrationThread = null; // No longer exists. }
/** * Get a free connection * * @return * @throws IllegalStateException - Thrown if a connection cannot be created. * @since 1.0.0 */ public IREMConnection getFreeConnection() throws IllegalStateException { Thread thread = Thread.currentThread(); if (thread instanceof REMCallbackThread) { // The current thread is a call back thread, so just reuse the connection. // But this thread could actually be trying to access another registry. // So if this thread is for this registry, use it, if not for this registry, create a new // connection. // But if for this registry AND is already in a transaction, we need a fresh connection. REMCallbackThread callbackThread = (REMCallbackThread) thread; if (callbackThread.registry == this && !callbackThread.inTransaction()) { // This way any calls out to the remote vm will be on same thread as callback caller // on remote vm because that thread is waiting on this connection for commands. IREMConnection c = (callbackThread).getConnection(); if (c.isConnected()) return c; else throw new IllegalStateException( ProxyRemoteMessages.REMProxyFactoryRegistry_CallbackConnectionNotWorking_EXC_); } } synchronized (fConnectionPool) { if (!fConnectionPool.isEmpty()) return (IREMConnection) fConnectionPool.pop(); // else we need to allocate one. return createConnection(); } }
/** Free the connection */ public void returnConnection(IREMConnection connection) { if (connection.isConnected()) { Thread thread = Thread.currentThread(); if (!(thread instanceof REMCallbackThread) || ((REMCallbackThread) thread).getConnection() != connection) { // We are not a callback thread, or we are but the connection is not for the thread, then // the connection // can be returned. synchronized (fConnectionPool) { if (fConnectionPool.size() < NUMBER_FREE_CONNECTIONS) fConnectionPool.push(connection); else connection.close(); // We don't need to maintain more than five free connections. } } } }
/* * Return whether the event handler is performing a background view update. * In other words, a client has invoked <code>performUpdate</code>. */ public boolean isPerformingBackgroundUpdate() { return Thread.currentThread() == getEventHandlerJob().getThread() && performingBackgroundUpdate; }
public void join() throws InterruptedException { if (job != null && job.getThread() != Thread.currentThread()) { job.join(); } }