How to receive data from multithread in Java using Custom Event Listener?












0















I have a about 500 threads(assume that call as X for all these threads), and these threads receive data from different restful services continuously. Also, i have 20 threads(assume that call as Y for all these threads) for receive data returned from other threads(from X).



Should I use BlockingQueue or Custom Event Listener? Which one is better?



Also, there should be no data loss.










share|improve this question



























    0















    I have a about 500 threads(assume that call as X for all these threads), and these threads receive data from different restful services continuously. Also, i have 20 threads(assume that call as Y for all these threads) for receive data returned from other threads(from X).



    Should I use BlockingQueue or Custom Event Listener? Which one is better?



    Also, there should be no data loss.










    share|improve this question

























      0












      0








      0








      I have a about 500 threads(assume that call as X for all these threads), and these threads receive data from different restful services continuously. Also, i have 20 threads(assume that call as Y for all these threads) for receive data returned from other threads(from X).



      Should I use BlockingQueue or Custom Event Listener? Which one is better?



      Also, there should be no data loss.










      share|improve this question














      I have a about 500 threads(assume that call as X for all these threads), and these threads receive data from different restful services continuously. Also, i have 20 threads(assume that call as Y for all these threads) for receive data returned from other threads(from X).



      Should I use BlockingQueue or Custom Event Listener? Which one is better?



      Also, there should be no data loss.







      java multithreading thread-safety streaming






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 1 at 16:10









      AdamR.AdamR.

      14118




      14118
























          3 Answers
          3






          active

          oldest

          votes


















          0














          Limitation of using BlockingQueue, it has a queue with a threshold point. Post this point, no more threads can be processed. In a scenario, Lost Data couldn't be recovered when exceptions (failures) are thrown by bunch of threads (X or Y) (which couldn't be processed again).



          However, Custom Event Listener is preferable approach where acknowledgment can be done for all thread, and in case of thread exception (failure), we can retrieve lost data by using some reprocess mechanism.



          Can use ReactiveX(Observable) library for this problem.






          share|improve this answer































            0














            Why don't you try a messaging queue( like Kafka, rabbitmq)
            which work like a data holder between the threads x and Y.
            You put data in queue from x's and fetch/process the data via Y's which is asynchronous.



            You should opt for this as even in Event Listener if we consider number of x 500 and y 20. then even for each call of x's there be 20 call (assume).which can become a bottle neck on heavy load.






            share|improve this answer































              0














              BlockingQueue is better (usually).






              share|improve this answer























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996948%2fhow-to-receive-data-from-multithread-in-java-using-custom-event-listener%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                0














                Limitation of using BlockingQueue, it has a queue with a threshold point. Post this point, no more threads can be processed. In a scenario, Lost Data couldn't be recovered when exceptions (failures) are thrown by bunch of threads (X or Y) (which couldn't be processed again).



                However, Custom Event Listener is preferable approach where acknowledgment can be done for all thread, and in case of thread exception (failure), we can retrieve lost data by using some reprocess mechanism.



                Can use ReactiveX(Observable) library for this problem.






                share|improve this answer




























                  0














                  Limitation of using BlockingQueue, it has a queue with a threshold point. Post this point, no more threads can be processed. In a scenario, Lost Data couldn't be recovered when exceptions (failures) are thrown by bunch of threads (X or Y) (which couldn't be processed again).



                  However, Custom Event Listener is preferable approach where acknowledgment can be done for all thread, and in case of thread exception (failure), we can retrieve lost data by using some reprocess mechanism.



                  Can use ReactiveX(Observable) library for this problem.






                  share|improve this answer


























                    0












                    0








                    0







                    Limitation of using BlockingQueue, it has a queue with a threshold point. Post this point, no more threads can be processed. In a scenario, Lost Data couldn't be recovered when exceptions (failures) are thrown by bunch of threads (X or Y) (which couldn't be processed again).



                    However, Custom Event Listener is preferable approach where acknowledgment can be done for all thread, and in case of thread exception (failure), we can retrieve lost data by using some reprocess mechanism.



                    Can use ReactiveX(Observable) library for this problem.






                    share|improve this answer













                    Limitation of using BlockingQueue, it has a queue with a threshold point. Post this point, no more threads can be processed. In a scenario, Lost Data couldn't be recovered when exceptions (failures) are thrown by bunch of threads (X or Y) (which couldn't be processed again).



                    However, Custom Event Listener is preferable approach where acknowledgment can be done for all thread, and in case of thread exception (failure), we can retrieve lost data by using some reprocess mechanism.



                    Can use ReactiveX(Observable) library for this problem.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 1 at 17:37









                    Prashant SinghPrashant Singh

                    496




                    496

























                        0














                        Why don't you try a messaging queue( like Kafka, rabbitmq)
                        which work like a data holder between the threads x and Y.
                        You put data in queue from x's and fetch/process the data via Y's which is asynchronous.



                        You should opt for this as even in Event Listener if we consider number of x 500 and y 20. then even for each call of x's there be 20 call (assume).which can become a bottle neck on heavy load.






                        share|improve this answer




























                          0














                          Why don't you try a messaging queue( like Kafka, rabbitmq)
                          which work like a data holder between the threads x and Y.
                          You put data in queue from x's and fetch/process the data via Y's which is asynchronous.



                          You should opt for this as even in Event Listener if we consider number of x 500 and y 20. then even for each call of x's there be 20 call (assume).which can become a bottle neck on heavy load.






                          share|improve this answer


























                            0












                            0








                            0







                            Why don't you try a messaging queue( like Kafka, rabbitmq)
                            which work like a data holder between the threads x and Y.
                            You put data in queue from x's and fetch/process the data via Y's which is asynchronous.



                            You should opt for this as even in Event Listener if we consider number of x 500 and y 20. then even for each call of x's there be 20 call (assume).which can become a bottle neck on heavy load.






                            share|improve this answer













                            Why don't you try a messaging queue( like Kafka, rabbitmq)
                            which work like a data holder between the threads x and Y.
                            You put data in queue from x's and fetch/process the data via Y's which is asynchronous.



                            You should opt for this as even in Event Listener if we consider number of x 500 and y 20. then even for each call of x's there be 20 call (assume).which can become a bottle neck on heavy load.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 2 at 6:45









                            SachinSachin

                            1115




                            1115























                                0














                                BlockingQueue is better (usually).






                                share|improve this answer




























                                  0














                                  BlockingQueue is better (usually).






                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    BlockingQueue is better (usually).






                                    share|improve this answer













                                    BlockingQueue is better (usually).







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jan 2 at 10:49









                                    Alexei KaigorodovAlexei Kaigorodov

                                    10.1k11229




                                    10.1k11229






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996948%2fhow-to-receive-data-from-multithread-in-java-using-custom-event-listener%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        MongoDB - Not Authorized To Execute Command

                                        How to fix TextFormField cause rebuild widget in Flutter

                                        in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith