• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iluwatar / java-design-patterns / #1674

06 Sep 2015 05:33PM UTC coverage: 85.286% (-0.4%) from 85.644%
#1674

push

Markus
Removed the Markdown Plus custom heading id's

Because the renderer of github doesnt support markdown plus...

3246 of 3806 relevant lines covered (85.29%)

0.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/poison-pill/src/main/java/com/iluwatar/poison/pill/App.java
1
package com.iluwatar.poison.pill;
2

3
/**
4
 * One of the possible approaches to terminate Producer-Consumer pattern is using the Poison Pill idiom.
5
 * If you use Poison Pill as the termination signal then Producer is responsible to notify Consumer that exchange is over
6
 * and reject any further messages. Consumer receiving Poison Pill will stop reading messages from the queue.
7
 * You must also ensure that the Poison Pill will be the last message that will be read from the queue (if you have
8
 * prioritized queue then this can be tricky).
9
 * <p>
10
 * In simple cases as Poison Pill can be used just null-reference, but holding unique separate shared
11
 * object-marker (with name "Poison" or "Poison Pill") is more clear and self describing.
12
 * 
13
 */
14
public class App {
×
15

16
        /**
17
         * Program entry point
18
         * @param args command line args
19
         */
20
        public static void main(String[] args) {
21
                MessageQueue queue = new SimpleMessageQueue(10000);
1✔
22

23
                final Producer producer = new Producer("PRODUCER_1", queue);
1✔
24
                final Consumer consumer = new Consumer("CONSUMER_1", queue);
1✔
25

26
                new Thread() {
1✔
27
                        @Override
28
                        public void run() {
29
                                consumer.consume();
×
30
                        }
×
31
                }.start();
1✔
32

33
                new Thread() {
1✔
34
                        @Override
35
                        public void run() {
36
                                producer.send("hand shake");
×
37
                                producer.send("some very important information");
×
38
                                producer.send("bye!");
×
39
                                producer.stop();
×
40
                        }
×
41
                }.start();
1✔
42
        }
1✔
43
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc