protected boolean insert ( E element , boolean unlockAndBlock ) { // Create a new record for the data item. SynchRecordImpl < E > record = new SynchRecordImpl < E > ( element ) ; boolean result = buffer . offer ( record ) ; if ( result ) { count ++ ; // Tell any waiting consumers that the queue is not empty. notEmpty . signal ( ) ; if ( unlockAndBlock ) { // Allow other threads to read/write the queue. lock . unlock ( ) ; // Wait until a consumer takes this data item. record . waitForConsumer ( ) ; } return true ; } else { return false ; } }
Insert element into the queue then possibly signal that the queue is not empty and block the producer on the element until permission to procede is given .