You could use an ExecutorService to fire up and shutdown the producer and consumer. HAve a look at its API, specifically the shutdown() / shutdownNow() and awaitTermination() methods.
An other way would be to use a "poison pill". When the producer is finished have it produce an object that is recognizable to the consumer as a shutdown indicator. That can get a bit involved though, when you have multiple producers and consumers hooked up to the same queue.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.