# Class AsyncBufferedIterator<T>

java.lang.Object
htsjdk.samtools.util.AsyncBufferedIterator<T>

All Implemented Interfaces:
  `CloseableIterator<T>, Closeable, AutoCloseable, Iterator<T>`

public class AsyncBufferedIterator<T> extends Object implements CloseableIterator<T>
Iterator that uses a dedicated background thread to perform read-ahead to improve throughput at the expense of increased latency. This iterator will block until the background thread has read a full buffer of records. Note that this implementation is not synchronized. If multiple threads access an instance concurrently, it must be synchronized externally.

## Constructor Summary

Constructors
Constructor
Description
`AsyncBufferedIterator(Iterator<T> iterator, int bufferSize)`
Creates a new iterator that traverses the given iterator on a background thread
`AsyncBufferedIterator(Iterator<T> iterator, int bufferSize, int bufferCount)`
Creates a new iterator that traverses the given iterator on a background thread
`AsyncBufferedIterator(Iterator<T> iterator, int bufferSize, int bufferCount, String threadName)`
Creates a new iterator that traverses the given iterator on a background thread

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Should be implemented to close/release any underlying resources.
`protected String`
`getThreadNamePrefix()`
`boolean`
`hasNext()`
`T`
`next()`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface CloseableIterator

`stream, toList`

### Methods inherited from interface Iterator

`forEachRemaining, remove`

## Constructor Details

### AsyncBufferedIterator

public AsyncBufferedIterator(Iterator<T> iterator, int bufferSize)
Creates a new iterator that traverses the given iterator on a background thread

Parameters:
  `iterator` - iterator to traverse
  `bufferSize` - size of read-ahead buffer. A larger size will increase both throughput and latency. Double buffering is used so the maximum number of records on which read-ahead is performed is twice this.

### AsyncBufferedIterator

public AsyncBufferedIterator(Iterator<T> iterator, int bufferSize, int bufferCount)
Creates a new iterator that traverses the given iterator on a background thread

Parameters:
  `iterator` - iterator to traverse
  `bufferSize` - size of each read-ahead buffer. A larger size will increase both throughput and latency.
  `bufferCount` - number of read-ahead buffers

### AsyncBufferedIterator

public AsyncBufferedIterator(Iterator<T> iterator, int bufferSize, int bufferCount, String threadName)
Creates a new iterator that traverses the given iterator on a background thread

Parameters:
  `iterator` - iterator to traverse
  `bufferSize` - size of each read-ahead buffer. A larger size will increase both throughput and latency.
  `bufferCount` - number of read-ahead buffers
  `threadName` - background thread name. A name will be automatically generated if this parameter is null.

## Method Details

### getThreadNamePrefix

protected String getThreadNamePrefix()

### close

public void close()
Description copied from interface: `CloseableIterator`
Should be implemented to close/release any underlying resources.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `CloseableIterator<T>`

### hasNext

public boolean hasNext()

Specified by:
  `hasNext` in interface `Iterator<T>`

### next

public T next()

Specified by:
  `next` in interface `Iterator<T>`