FileDocCategorySizeDatePackage
LockSupportTest.javaAPI DocAndroid 1.5 API4530Wed May 06 22:41:02 BST 2009tests.api.java.util.concurrent

LockSupportTest

public class LockSupportTest extends JSR166TestCase

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        junit.textui.TestRunner.run (suite());        
    
public static junit.framework.Testsuite()

        return new TestSuite(LockSupportTest.class);
    
public voidtestPark()
park is released by unpark occurring after park

 
        Thread t = new Thread(new Runnable() {
                public void run() {
                    try {
                        LockSupport.park();
                    } catch(Exception e){
                        threadUnexpectedException();
                    }
                }
            });
        try {
            t.start();
            Thread.sleep(SHORT_DELAY_MS);
            LockSupport.unpark(t);
            t.join();
        }
        catch(Exception e) {
            unexpectedException();
        }
    
public voidtestPark2()
park is released by unpark occurring before park

 
        Thread t = new Thread(new Runnable() {
                public void run() {
                    try {
                        Thread.sleep(SHORT_DELAY_MS);
                        LockSupport.park();
                    } catch(Exception e){
                        threadUnexpectedException();
                    }
                }
            });
        try {
            t.start();
            LockSupport.unpark(t);
            t.join();
        }
        catch(Exception e) {
            unexpectedException();
        }
    
public voidtestPark3()
park is released by interrupt

 
        Thread t = new Thread(new Runnable() {
                public void run() {
                    try {
                        LockSupport.park();
                        threadAssertTrue(Thread.interrupted());
                    } catch(Exception e){
                        threadUnexpectedException();
                    }
                }
            });
        try {
            t.start();
            Thread.sleep(SHORT_DELAY_MS);
            t.interrupt();
            t.join();
        }
        catch(Exception e) {
            unexpectedException();
        }
    
public voidtestPark4()
park returns if interrupted before park

 
        final ReentrantLock lock = new ReentrantLock();
        lock.lock();
        Thread t = new Thread(new Runnable() {
                public void run() {
                    try {
                        lock.lock();
                        LockSupport.park();
                    } catch(Exception e){
                        threadUnexpectedException();
                    }
                }
            });
        try {
            t.start();
            t.interrupt();
            lock.unlock();
            t.join();
        }
        catch(Exception e) {
            unexpectedException();
        }
    
public voidtestParkNanos()
parkNanos times out if not unparked

 
        Thread t = new Thread(new Runnable() {
                public void run() {
                    try {
                        LockSupport.parkNanos(1000);
                    } catch(Exception e){
                        threadUnexpectedException();
                    }
                }
            });
        try {
            t.start();
            t.join();
        }
        catch(Exception e) {
            unexpectedException();
        }
    
public voidtestParkUntil()
parkUntil times out if not unparked

 
        Thread t = new Thread(new Runnable() {
                public void run() {
                    try {
                        long d = new Date().getTime() + 100;
                        LockSupport.parkUntil(d);
                    } catch(Exception e){
                        threadUnexpectedException();
                    }
                }
            });
        try {
            t.start();
            t.join();
        }
        catch(Exception e) {
            unexpectedException();
        }