Package org.clapper.util.misc

Examples of org.clapper.util.misc.Semaphore


        private void doTest()
            throws SemaphoreException
        {
            boolean acquired = false;
            Semaphore semaphore = TestSemaphore.this.semaphore;
            Semaphore parentSem = TestSemaphore.this.parentSem;
            int holdTime = TestSemaphore.this.holdTime;
            int pendTime = TestSemaphore.this.pendTime;

            message ("Acquiring " + semaphore.toString() +
                     ", pendTime = " + pendTime);

            acquired = semaphore.acquire (pendTime);
            if (! acquired)
                message ("*** Failed to acquire semaphore.");

            else
            {
                // Synchronize on something else, to test deadlock.

                synchronized (TestSemaphore.class)
                {
                    message ("Got semaphore " + semaphore + ". Waiting " +
                             holdTime + " milliseconds.");
                }

                try
                {
                    Thread.yield();
                    Thread.sleep (holdTime);
                }

                catch (InterruptedException ex)
                {
                }

                synchronized (TestSemaphore.class)
                {
                    message ("Releasing semaphore " + semaphore + ".");

                }

                semaphore.release();
            }

            message ("Notifying parent.");
            parentSem.release();
            message ("Exiting.");
        }
View Full Code Here

TOP

Related Classes of org.clapper.util.misc.Semaphore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.