User: jung    
  Date: 00/12/22 07:43:26

  Added:       src/de/infor/ce/thread/test ThreadPool.java test.dfPackage
  Log:
  repackaged thread pooling. Coherent environment. Exception extensions.
  
  Revision  Changes    Path
  1.1                  zoap/src/de/infor/ce/thread/test/ThreadPool.java
  
  Index: ThreadPool.java
  ===================================================================
  /*
   *    $Id: ThreadPool.java,v 1.1 2000/12/22 15:43:25 jung Exp $
   *    Copyright 2000 (C) infor:business solutions AG, Hauerstrasse 12,
   *    D-66299 Friedrichsthal, Germany. All Rights Reserved.
   *
   *    License Statement
   *
   *    Redistribution and use of this software and associated documentation 
("Software"), with or without
   *    modification, are permitted provided that the following conditions are met:
   *
   *    1.      Redistributions of source code must retain copyright statements and 
notices.
   *            Redistributions must also contain a copy of this document.
   *
   *    2.      Redistributions in binary form must reproduce the attached copyright 
notice, this list of
   *            conditions and the following disclaimer in the documentation and/or 
other materials provided
   *            with the distribution.
   *
   *    3.      The end-user documentation included with the redistribution, if any, 
must include the following
   *            acknowledgment: "This product includes software developed by infor: 
business solutions AG
   *            (http://www.infor.de/)." Alternately, this acknowledgment may appear 
in the software itself,
   *            if and wherever such third-party acknowledgments normally appear.
   *
   *    4.      The name "infor" must not be used to endorse or promote products 
derived from this
   *            Software without prior written permission of infor: business solutions 
AG.
   *            For written permission, please contact [EMAIL PROTECTED]
   *
   *    5.      Products derived from this Software may not be called "infor" nor may 
"infor" appear
   *            in their names without prior written permission of infor: business 
solutions AG. infor
   *            is a registered trademark of infor:business solutions AG.
   *
   *    Disclaimer
   *
   *    THIS SOFTWARE IS PROVIDED BY INFOR: BUSINESS SOLUTIONS AG AND CONTRIBUTORS "AS 
IS" AND ANY
   *    EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF
   *    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   *
   *    IN NO EVENT SHALL INFOR: BUSINESS SOLUTIONS AG OR ITS CONTRIBUTORS BE LIABLE 
FOR ANY DIRECT,
   *    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO,
   *    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
BUSINESS INTERRUPTION)
   *    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
LIABILITY, OR TORT
   *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
SOFTWARE,
   *    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   */
  
  package de.infor.ce.thread.test;
  
  import de.infor.ce.thread.PooledThreadLocal;
  
  /**
   *      A unit test for checking low-level features of the threadpool
   *      @see <related>
   *      @author $Author: jung $
   *      @version $Revision: 1.1 $
   */
  
  public class ThreadPool extends junit.framework.TestCase {
  
        public ThreadPool(String name) {
                super(name);
        }
  
        public static void main(String[] args) {
  
                junit.textui.TestRunner runner = new junit.textui.TestRunner();
  
                try {
                        runner.run(suite());
                } catch (Exception e) {
                }
        }
  
        public static junit.framework.Test suite() {
                return new junit.framework.TestSuite(ThreadPool.class);
        }
  
        de.infor.ce.thread.ThreadPool threadPool;
  
        ThreadLocal threadLocal;
  
        public void setUp() {
                threadPool = new de.infor.ce.thread.ThreadPool(32,
                false, "pool", false);
                threadLocal = new de.infor.ce.thread.PooledThreadLocal();
                running = true;
        }
  
        public boolean running;
  
        class BadTask implements Runnable {
                public void run() {
  
                        try {
                                while (running) {
                                        synchronized(ThreadPool.this) {
                                                try {
                                                        ThreadPool.this.wait(1000);
                                                } catch (InterruptedException e) {
                                                }
                                        }
                                }
                        } catch (Exception e) {
                                fail("unknown exception thrown in BadTask.run()");
                        }
                }
        }
  
  
        class GoodTask implements Runnable {
                public void run() {
                        if (threadLocal.get() != null)
                                fail("threadlocal has not been cleared after reuse");
                        threadLocal.set(
                            new Object());
                }
        }
  
  
        public void testThreadPoolBad() {
  
                for (int count = 0; count < 64; count++)
                        threadPool.run(
                            new BadTask());
  
                threadPool.run(
                    new BadTask());
  
                threadPool.finalize();
  
                running = false;
  
        } // testHttp
  
        public void testThreadPoolGood() {
  
                for (int count = 0; count < 64; count++)
                        threadPool.run(
                            new GoodTask());
  
                threadPool.run(
                    new GoodTask());
  
                threadPool.finalize();
  
                running = false;
  
        } // testHttp
  
        public void tearDown() {
                threadPool.finalize();
                running = false;
        }
  
  } // ThreadPool
  
  
  
  
  1.1                  zoap/src/de/infor/ce/thread/test/test.dfPackage
  
  Index: test.dfPackage
  ===================================================================
  package id2p4gtcamcwfvycamcygzi;
  
  /**
  @version 2.0
  @physicalPackage
  @__modelType diagram 
  */
  class diagram {
  /**
  @__ref <oiref:java#Class#de.infor.ce.thread.test.ThreadPool:oiref><oihard>
  @__modelType reference 
  */
  class reference {
  }}/**
  @__tags
  @shapeType ClassDiagram 
  */
  class __tags {
  }/**
  @__options 
  */
  class __options {
  }/**
  @__positions 
  */
  class __positions {
  }
  
  
  

Reply via email to