public void add ( final T bagEntry ) { if ( closed ) { LOGGER . info ( "ConcurrentBag has been closed, ignoring add()" ) ; throw new IllegalStateException ( "ConcurrentBag has been closed, ignoring add()" ) ; } sharedList . add ( bagEntry ) ; // spin until a thread takes it or none are waiting while ( waiters . get ( ) > 0 && bagEntry . getState ( ) == STATE_NOT_IN_USE && ! handoffQueue . offer ( bagEntry ) ) { yield ( ) ; } }
Add a new object to the bag for others to borrow .