Question: I understand threads in theory, but I have no idea how to implement them in Java. 

![setup](https://i.imgur.com/xIk6S.png)

The circles are supposed to be threads and the rectangles are supposed to be buffers.

I have this all coded but it doesn't work, so I am starting new. My source of confusion comes from the fact that I need this cycle to repeat many times and in this order, but I can't predict what thread will run first. If thread B that relies in data from A runs first, what happens?

Also how can I keep the threads running indefinitely?

Answer: 
1. You can programatically start one
thread before the other. Then in a
simple java program you can be
pretty sure which thread will start
first (because you decide!)
2. You can make thread B blocked on
empty buffer or queue (depends if
your thread B is a retriever and
parser)

You can find more literature on this topic by using keywords such as 'concurrency', 'producer' and 'consumer'
<http://www.java2s.com/Code/Java/Threads/Producer-Consumer.htm>