Package EDU.oswego.cs.dl.util.concurrent

Examples of EDU.oswego.cs.dl.util.concurrent.CountDown


        tp.doStop();
    }

    public void setUp() throws Exception {
        completed = new CountDown(COUNT);
    }
View Full Code Here


        tp.doStop();
    }

    public void setUp() throws Exception {
        completed = new CountDown(COUNT);
    }
View Full Code Here

                         CopletInstanceData coplet,
                         ContentHandler handler) {
        this.adapter = adapter;
        this.coplet  = coplet;
        this.handler = handler;
        this.finished = new CountDown( 1 );
    }
View Full Code Here

        public LoaderThread(Source source,
                            XMLSerializer serializer,
                            ServiceManager manager) {
            this.source = source;
            this.serializer = serializer;
            this.finished = new CountDown( 1 );
            this.manager = manager;
        }
View Full Code Here

    public void testConcurrentRequests() throws Exception {

        final int WORKERS = 100;
        final int MESSAGE_COUNT = 10;
        final CyclicBarrier barrier = new CyclicBarrier(WORKERS);
        final CountDown finished = new CountDown(WORKERS);

        for (int i = 0; i < WORKERS; i++) {

            new Thread() {
                /**
                 * @see java.lang.Thread#run()
                 */
                public void run() {
                    try {
                        barrier.barrier();

                        for (int i = 0; i < MESSAGE_COUNT; i++)
                            sp.sendDown(getDatagramPacket());


                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        finished.release();
                    }
                }
            }.start();
        }

        finished.acquire();

        Thread.sleep(5 * 1000);

        assertEquals(WORKERS * MESSAGE_COUNT, count);
    }
View Full Code Here

      if(str == null)
         throw new RuntimeException("Can't find update_pojo_interval property");

      updatePojoInterval_ = Integer.parseInt(str);

      countdown_ = new CountDown(threads_);

      // Warm up the cache first to avoid any simultaneous write contention.
      if(cache_.getCoordinator().equals(cache_.getLocalAddress()))
      {
         System.out.println("I am the coordinator: " +cache_.getLocalAddress());
View Full Code Here

      if(str == null)
         throw new RuntimeException("Can't find update_pojo_interval property");

      updatePojoInterval_ = Integer.parseInt(str);

      countdown_ = new CountDown(threads_);

      // Warm up the cache first to avoid any simultaneous write contention.
      if(cache_.getCoordinator().equals(cache_.getLocalAddress()))
      {
         System.out.println("I am the coordinator: " + cache_.getLocalAddress());
View Full Code Here

      threadSafetyTest(false);
   }

   protected void threadSafetyTest(final boolean singleFqn) throws Exception
   {
      final CountDown latch = new CountDown(1);
      final Fqn fqn = Fqn.fromString("/a/b/c");
      final List fqns = new ArrayList(30);
      final Random r = new Random();
      if (!singleFqn)
      {
         for (int i = 0; i < 30; i++)
         {
            Fqn f = Fqn.fromString("/a/b/c/" + i);
            fqns.add(f);
            loader.put(f, "k", "v");
         }
      }
      else
      {
         loader.put(fqn, "k", "v");
      }
      final int loops = 1000;
      final Set exceptions = new CopyOnWriteArraySet();

      Thread remover1 = new Thread("Remover-1")
      {
         public void run()
         {
            try
            {
               latch.acquire();
               for (int i = 0; i < loops; i++)
               {
                  loader.remove(singleFqn ? fqn : (Fqn)fqns.get(r.nextInt(fqns.size())));
               }
            }
            catch (Exception e)
            {
               exceptions.add(e);
            }
         }
      };

      remover1.start();

      Thread remover2 = new Thread("Remover-2")
      {
         public void run()
         {
            try
            {
               latch.acquire();
               for (int i = 0; i < loops; i++)
               {
                  loader.remove(singleFqn ? fqn : (Fqn)fqns.get(r.nextInt(fqns.size())), "k");
               }
            }
            catch (Exception e)
            {
               exceptions.add(e);
            }
         }
      };

      remover2.start();


      Thread reader1 = new Thread("Reader-1")
      {
         public void run()
         {
            try
            {
               latch.acquire();
               for (int i = 0; i < loops; i++)
               {
                  loader.get(singleFqn ? fqn : (Fqn)fqns.get(r.nextInt(fqns.size())));
               }
            }
            catch (Exception e)
            {
               exceptions.add(e);
            }
         }
      };
      reader1.start();

      Thread reader2 = new Thread("Reader-2")
      {
         public void run()
         {
            try
            {
               latch.acquire();
               for (int i = 0; i < loops; i++)
               {
                  loader.getChildrenNames(singleFqn ? fqn : (Fqn)fqns.get(r.nextInt(fqns.size())));
               }
            }
            catch (Exception e)
            {
               exceptions.add(e);
            }
         }
      };
      reader2.start();


      Thread writer1 = new Thread("Writer-1")
      {
         public void run()
         {
            try
            {
               latch.acquire();
               for (int i = 0; i < loops; i++)
               {
                  loader.put(singleFqn ? fqn : (Fqn)fqns.get(r.nextInt(fqns.size())), "k", "v");
               }
            }
            catch (Exception e)
            {
               exceptions.add(e);
            }
         }
      };
      writer1.start();

      Thread writer2 = new Thread("Writer-2")
      {
         public void run()
         {
            try
            {
               latch.acquire();
               for (int i = 0; i < loops; i++)
               {
                  loader.put(singleFqn ? fqn : (Fqn)fqns.get(r.nextInt(fqns.size())), new HashMap());
               }
            }
            catch (Exception e)
            {
               exceptions.add(e);
            }
         }
      };
      writer2.start();


      latch.release();
      reader1.join();
      reader2.join();
      remover1.join();
      remover2.join();
      writer1.join();
View Full Code Here

       threadSafetyTest(false);
    }

    protected void threadSafetyTest(final boolean singleFqn) throws Exception
    {
       final CountDown latch = new CountDown(1);
       final Fqn fqn = Fqn.fromString("/a/b/c");
       final List fqns = new ArrayList(30);
       final Random r = new Random();
       if (!singleFqn)
       {
          for (int i = 0; i < 30; i++)
          {
             Fqn f = Fqn.fromString("/a/b/c/" + i);
             fqns.add(f);
             cache2.put(f, "k", "v");
             cache1.evict(f);
          }
       }
       else
       {
          cache2.put(fqn, "k", "v");
          cache1.evict(fqn);
       }
       final int loops = 10000;
       final Set exceptions = new CopyOnWriteArraySet();

       Thread evictor = new Thread("Evictor")
       {
          public void run()
          {
             try
             {
                latch.acquire();
                for (int i = 0; i < loops; i++)
                {
                   Fqn f = singleFqn ? fqn : (Fqn)fqns.get(r.nextInt(fqns.size()));
                   cache1.evict(f);
                }
             }
             catch (TimeoutException te)
             {
                // doesn't matter if we hit these on occasion
             }
             catch (Exception e)
             {
                exceptions.add(e);
             }
          }
       };

       evictor.start();

       Thread writer = new Thread("Writer")
       {
          public void run()
          {
             try
             {
                latch.acquire();
                for (int i = 0; i < loops; i++)
                {
                   Fqn f = singleFqn ? fqn : (Fqn)fqns.get(r.nextInt(fqns.size()));
                   cache2.put(f, "k", "v");
                }
             }
             catch (Exception e)
             {
                exceptions.add(e);
             }
          }
       };

       writer.start();


       Thread reader1 = new Thread("Reader-1")
       {
          public void run()
          {
             try
             {
                latch.acquire();
                for (int i = 0; i < loops; i++)
                {
                   loader1.get(singleFqn ? fqn : (Fqn)fqns.get(r.nextInt(fqns.size())));
                }
             }
             catch (Exception e)
             {
                exceptions.add(e);
             }
          }
       };
       reader1.start();

       Thread reader2 = new Thread("Reader-2")
       {
          public void run()
          {
             try
             {
                latch.acquire();
                for (int i = 0; i < loops; i++)
                {
                   loader1.getChildrenNames(singleFqn ? fqn.getParent() : ((Fqn)fqns.get(r.nextInt(fqns.size()))).getParent());
                }
             }
             catch (Exception e)
             {
                exceptions.add(e);
             }
          }
       };
       reader2.start();

       Thread reader3 = new Thread("Reader-3")
       {
          public void run()
          {
             try
             {
                latch.acquire();
                for (int i = 0; i < loops; i++)
                {
                   loader1.getChildrenNames(singleFqn ? fqn : (Fqn)fqns.get(r.nextInt(fqns.size())));
                }
             }
             catch (Exception e)
             {
                exceptions.add(e);
             }
          }
       };
       reader3.start();

       latch.release();
       reader1.join();
       reader2.join();
       reader3.join();
       evictor.join();
       writer.join();
View Full Code Here

            {
                getLogger().error( "Cannot get RunnableManager", se );
                throw new IOException( "Cannot get RunnableManager" );
            }

            final CountDown done = new CountDown( 1 );
            StreamPumper errPumper = new StreamPumper(compilerErr, tmpErr, done);
            runnableManager.execute( errPumper );
            m_serviceManager.release( runnableManager );

            p.waitFor();
            exitValue = p.exitValue();

            done.acquire(); // Wait for StreadmPumper to finish
            compilerErr.close();

            p.destroy();

            tmpErr.close();
View Full Code Here

TOP

Related Classes of EDU.oswego.cs.dl.util.concurrent.CountDown

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.