Source:
<code>public void run() { try { _task.acquire(ACQUIRE_TIMEOUT); _lineNo = loadCheckpoint(); <START> _positionValue.setLinesSeen(Long.valueOf(_lineNo)); <END> while (!_cancelRequested) { String text; try { text = _fileReader.readLine(); _positionValue.setBytesRead(_inputStream.getCount()); } catch (IOException e) { throw new RuntimeException("Reading file failed.", e); } if (text != null) { HashMap<String, String> eventMetadata = new HashMap<>(); long currentTimeMillis = System.currentTimeMillis(); eventMetadata.put(BrooklinEnvelopeMetadataConstants.EVENT_TIMESTAMP, String.valueOf(currentTimeMillis)); BrooklinEnvelope event = new BrooklinEnvelope(_lineNo.toString().getBytes(), text.getBytes(), null, eventMetadata); LOG.info("sending event " + text); DatastreamProducerRecordBuilder builder = new DatastreamProducerRecordBuilder(); builder.addEvent(event); builder.setEventsSourceTimestamp(currentTimeMillis); if (!_task.isUserManagedDestination()) { builder.setPartition(0); } else { builder.setPartitionKey(_lineNo.toString()); } builder.setSourceCheckpoint(_lineNo.toString()); _producer.send(builder.build(), (metadata, exception) -> { if (exception == null) { LOG.info("Sending event:{} succeeded, metadata:{}", text, metadata); } else { LOG.error(String.format("Sending event:{%s} failed, metadata:{%s}", text, metadata), exception); } }); ++_lineNo; _positionValue.setLinesSeen(Long.valueOf(_lineNo)); } else { try { Thread.sleep(POLL_WAIT_MS); } catch (InterruptedException e) { LOG.info("Interrupted"); break; } } } _task.release(); _isStopped = true; LOG.info("Stopped at line " + _lineNo + " task=" + _task); } catch (Throwable e) { LOG.error("File processor is quitting with exception, task=" + _task, e); } }</code><technical_language>Is this/does thread safe</technical_language>

Target:
public void run() { try { _task.acquire(ACQUIRE_TIMEOUT); _lineNo = loadCheckpoint(); _positionValue.setLinesRead(Long.valueOf(_lineNo)); while (!_cancelRequested) { String text; try { text = _fileReader.readLine(); _positionValue.setBytesRead(_inputStream.getCount()); } catch (IOException e) { throw new RuntimeException("Reading file failed.", e); } if (text != null) { HashMap<String, String> eventMetadata = new HashMap<>(); long currentTimeMillis = System.currentTimeMillis(); eventMetadata.put(BrooklinEnvelopeMetadataConstants.EVENT_TIMESTAMP, String.valueOf(currentTimeMillis)); BrooklinEnvelope event = new BrooklinEnvelope(_lineNo.toString().getBytes(), text.getBytes(), null, eventMetadata); LOG.info("sending event " + text); DatastreamProducerRecordBuilder builder = new DatastreamProducerRecordBuilder(); builder.addEvent(event); builder.setEventsSourceTimestamp(currentTimeMillis); if (!_task.isUserManagedDestination()) { builder.setPartition(0); } else { builder.setPartitionKey(_lineNo.toString()); } builder.setSourceCheckpoint(_lineNo.toString()); _producer.send(builder.build(), (metadata, exception) -> { if (exception == null) { LOG.info("Sending event:{} succeeded, metadata:{}", text, metadata); } else { LOG.error(String.format("Sending event:{%s} failed, metadata:{%s}", text, metadata), exception); } }); ++_lineNo; _positionValue.setLinesRead(Long.valueOf(_lineNo)); } else { try { Thread.sleep(POLL_WAIT_MS); } catch (InterruptedException e) { LOG.info("Interrupted"); break; } } } _task.release(); _isStopped = true; LOG.info("Stopped at line " + _lineNo + " task=" + _task); } catch (Throwable e) { LOG.error("File processor is quitting with exception, task=" + _task, e); } }