Package freenet.support

Source Code of freenet.support.SerialExecutorTest

package freenet.support;

import freenet.node.PrioRunnable;
import freenet.support.io.NativeThread;
import junit.framework.TestCase;

public class SerialExecutorTest extends TestCase {
 
  public void testBlocking() {
    SerialExecutor exec = new SerialExecutor(NativeThread.NORM_PRIORITY);
    exec.start(new PooledExecutor(), "test");
    final MutableBoolean flag = new MutableBoolean();
    exec.execute(new PrioRunnable() {

      @Override
      public void run() {
        try {
          // Do nothing
        } finally {
          synchronized(flag) {
            flag.value = true;
            flag.notifyAll();
          }
        }
       
      }

      @Override
      public int getPriority() {
        return NativeThread.NORM_PRIORITY;
      }
     
    });
    synchronized(flag) {
      while(!flag.value) {
        try {
          flag.wait();
        } catch (InterruptedException e) {
          // Ignore
        }
      }
    }
  }

}
TOP

Related Classes of freenet.support.SerialExecutorTest

TOP
Copyright © 2018 www.massapi.com. 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.