Package java.lang

Examples of java.lang.Thread$Cleanup


      principal();
         }catch(Exception e){
       try{
    System.out.println("Atencion: \n asegurece de que la cuenta solo sea numeros \n y el balance tambien");
       sleep(5000);
      Thread menu2=new Thread(new Menu());
           menu2.start();
         }catch(Exception a){System.out.println("Error el proceso no puede parar");}
    }
         
     }   
View Full Code Here


    @Ignore //Race Condition
    @Test
    public void threeThreadsTryingToAcquireLockForTheSameFS() throws Exception {
        FSThread fsThread1 = new FSThread( fs1, lockService );
        Thread t1 = new Thread( fsThread1 );
        FSThread fsThread2 = new FSThread( fs1, lockService );
        Thread t2 = new Thread( fsThread2 );
        FSThread fsThread3 = new FSThread( fs1, lockService );
        Thread t3 = new Thread( fsThread3 );

        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();

        assertTrue( fsThread1.whenITookLock() < fsThread2.whenITookLock() );
        assertTrue(fsThread2.whenITookLock() < fsThread3.whenITookLock());
        assertMinDeltas( fsThread1, fsThread2, fsThread3 );
    }
View Full Code Here

      mLateWindow = TIME_UNIT.convert(lateWindow, unit);
      mStreamIndex = streamIndex;
     
      // create and start the thread

      Thread t = new Thread(name)
      {
        public void run()
        {
          try
          {
            log.debug("thread started");
           
            boolean isDone = false;
            DelayedItem<IMediaData> delayedItem = null;
           
            // wait for all the other stream threads to wakeup
            synchronized (SelfServicingMediaQueue.this)
            {
              mIsInitialized = true;
              SelfServicingMediaQueue.this.notifyAll();
            }
            // start processing media
           
            while (!isDone)
            {
              // synchronized (SelfServicingMediaQueue.this)
             
              mLock.lock();
              try
              {
                // while not done, and no item, wait for one
               
                while (!mDone && (delayedItem = mQueue.poll()) == null)
                {
                  try
                  {
                    mCondition.await();
                  }
                  catch (InterruptedException e)
                  {
                    // interrupt and return
                    Thread.currentThread().interrupt();
                   
                    return;
                  }
                }
               
                // notify the queue that data extracted
               
                mCondition.signalAll();
               
                // record "atomic" done
               
                isDone = mDone;
              }
              finally
              {
                mLock.unlock();
              }
             
              // if there is an item, dispatch it
              if (null != delayedItem)
              {
                IMediaData item = delayedItem.getItem();
               
                try
                {
                  do
                  {
                    // this is the story of goldilocks testing the the media
                   
                    long now = getMediaTime();
                    long delta = delayedItem.getTimeStamp() - now;
                   
                    // if the media is too new and unripe, goldilocks sleeps
                    // for a bit
                   
                    if (delta >= mEarlyWindow)
                    {
                      //debug("delta: " + delta);
                      try
                      {
                        //sleep(MILLISECONDS.convert(delta - mEarlyWindow, TIME_UNIT));
                        sleep(MILLISECONDS.convert(delta / 3, TIME_UNIT));
                      }
                      catch (InterruptedException e)
                      {
                        // interrupt and return
                        Thread.currentThread().interrupt();
                        return;
                      }
                    }
                    else
                    {
                      // if the media is old and moldy, goldilocks says
                      // "ick" and drops the media on the floor
                     
                      if (delta < -mLateWindow)
                      {
                        debug(
                          "@%5d DROP queue[%2d]: %s[%5d] delta: %d",
                          MILLISECONDS.convert(now, TIME_UNIT),
                          mQueue.size(),
                          (item instanceof IVideoPicture ? "IMAGE"
                            : "sound"), MILLISECONDS.convert(delayedItem
                              .getTimeStamp(), TIME_UNIT), MILLISECONDS.convert(
                                delta, TIME_UNIT));
                      }
                     
                      // if the media is just right, goldilocks dispaches it
                      // for presentiation becuse she's a badass bitch
                     
                      else
                      {
                        dispatch(item, delayedItem.getTimeStamp());
                       
                        // debug("%5d show [%2d]: %s[%5d] delta: %d",
                        // MILLISECONDS.convert(getPresentationTime(), TIME_UNIT),
                        // size(),
                        // (delayedItem.getItem() instanceof BufferedImage
                        // ? "IMAGE"
                        // : "sound"),
                        // MILLISECONDS.convert(delayedItem.getTimeStamp(),
                        // TIME_UNIT),
                        // MILLISECONDS.convert(delta, TIME_UNIT));
                      }
                     
                      // and the moral of the story is don't mess with goldilocks
                     
                      break;
                    }
                  }
                  while (!mDone);
                }
                finally
                {
                  if (item != null)
                    item.delete();
                }
              }
            }
          }
          finally
          {
            // close stats frame
           
            if (null != mStatsFrame)
            {
              mStatsFrame.dispose();
              mStatsFrame = null;
            }
           
            // close frame for this queue
           
            MediaFrame frame = mFrames.get(mStreamIndex);
            if (null != frame)
              frame.dispose();
          }
        }
      };

      t.setPriority(priority);
      t.setDaemon(true);

      synchronized (this)
      {
        t.start();
        try
        {
          while (!mIsInitialized)
            this.wait();
        }
View Full Code Here

TOP

Related Classes of java.lang.Thread$Cleanup

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.