Untangling a String with a Thread (see what I did there…?)

private ExecutorService executorService = Executors.newFixedThreadPool(1);
private ArrayBlockingQueue visionReaderQueue= new ArrayBlockingQueue(1000,true);
import java.util.concurrent.ArrayBlockingQueue;

public class VisionQueueReader implements Runnable {
private ArrayBlockingQueue queue;
public VisionQueueReader(ArrayBlockingQueue queue) {
this.queue = queue;
}
@Override
public void run() {
while (!Thread.interrupted()) {
try {
String messageFromQueue = queue.take();
//Here is where you do whatever processing on the json you need to…chance are this class might also have a Static reference to the Subsystem waiting for the message
} catch (InterruptedException e) {
break;
//this gets tripped when you shut the ExecutorServiceDown…the loop ends
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
}
executorService.shutdownNow();
executorService.submit(new VisionQueueReader(visionMessageQueue));

--

--

--

Husband and Father. Wilderness First-Aid Certified. Terrible at tying knots. I play Squash. I like things that Trade. Leafs fan. FRC and Scouts Canada

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Python Libraries to Visualize Molecular Crystals

Ruby vs Elixir performance ; Ultron is dead, long live UltronX

Logistics App Development: The Best Solutions and Technologies

Hi Greg, nice list.

HackTheBox Writeup — Wall

Types of Streams: Asynchronous Programming with Dart

Reusable Widgets & Reusable Custom AppBars in Flutter.

Breaking the database CI speed limit with Spawn

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jamie McIlroy

Jamie McIlroy

Husband and Father. Wilderness First-Aid Certified. Terrible at tying knots. I play Squash. I like things that Trade. Leafs fan. FRC and Scouts Canada

More from Medium

Analyse the cost of your algorithms

Inheritance

What is the FLP Impossibility Result?

Anonymous Inner Classes