Or if it is not used a lot, you can do

    Option(unusedFileIds.poll()).getOrElse(nextFileId.getAndIncrement())