Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8545869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:53:26+00:00 2026-06-11T12:53:26+00:00

I am building a Java EE application that includes functionality to process AMQP topics.

  • 0

I am building a Java EE application that includes functionality to process AMQP “topics”. My idea is to create a Listener class that is initialized via the contextInitialized method of javax.servlet.ServletContextEvent.

This class would run two separate threads; one would listen for messages and add the received messages to a FIFO queue and the second would process the messages from the queue. The reason for this is that I don’t what the AMQP client to be impacted by delays in processing the messages.

In a complex application that has multiple “Listeners”, I could end up with a large number of threads running asynchronous tasks. I am not experienced enough to know from an architectural perspective if breaking an application up into multiple threads in this way is a reasonable approach?

Maybe each message should be processed in its “own” thread rather than by a queue process. Any advice or guidance regarding either the use of multiple threads to manage application flow or the approach that I have proposed would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:53:27+00:00Added an answer on June 11, 2026 at 12:53 pm

    Running stuff in separate threads does not necessarily make them go faster.

    The throughput of a system running on a single machine is limited by the processing bandwidth of the machine; i.e. number and speed of cores, the memory system, disc and network I/O and so on. In a multi-threaded application, the threads all effectively share the resources. So for instance, if you have more runnable threads than cores at a given instant, some of the threads will be waiting to be scheduled to a code.

    The second issue is that threads typically need to communicate with each other and / or update shared data structures. Both of these entail some kind of synchronization. If you have a lot of this going on, there is a potential for the synchronization to become a bottleneck that reduces throughput.


    So how does this apply to your system? Well, the potential problem is that the extra threads that are doing the background processing are going to use resources, and if there is too much work for the threads:
    – they may not be able to keep up, and the queue lengths could get out of control, resulting in long delays and worse, and
    – this could interfere with the listeners’ ability to accept new messages.

    From a performance perspective, one thing you want to avoid is having too many threads. Beyond a certain point (which depends on the application), adding more threads can actually reduce throughput for a variety of reasons. As a rule of thumb, try to limit the number threads to 1 to 2 times the number of cores.

    If you think that it is likely that your system will be swamped with more messages that it can handle, it needs to be designed so that it can shed load; e.g. by stopping accepting new requests, or dumping existing ones. You do not want unbounded queues or an unbounded numbers of worker threads, and these can lead to catastrophic feedback and systems collapsing / crashing under heavy load. (And also be aware that heavy load is going to lead to more contention and increase the chance of failures due to undetected concurrency bugs.)


    Updates:

    1. It seems that AMQP has a built-in flow control mechanism using “flow frames”. You should probably be trying to leverage that rather do your own flow control / load management internally.
    2. Message persistence per se won’t help. While you can buffer a huge amount message traffic, it won’t help you deal with a mismatch between the message production and processing rates. (The persistence mechanism will also result in slower message transfer rates, though that probably isn’t a concern for you.)
    3. Doing separate phases of processing on different services can increase throughput, though the flip-side is that you have more messaging overheads. Bottom line is that this kind of partitioning can reduce throughput instead of increasing it.
    4. If you want your solution to scale up, you need to design it so that you can replicate your servers; e.g. instead of having new requests go to one server, split them across N servers with independent persistence back-ends.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're in the process of building an internal, Java-based RESTful web services application that
I'm building a Java application that has parts that require daily update. I want
I'm building a large Java application that uses multiple pop-up windows. Some of these
I am building a Java SE application that is powered by Hibernate. Mainly many
I'm currently working on a project that is building a java-based desktop application to
I'm building a web application which will include functionality that takes MS Word (and
I'm building a Java application with a Swing GUI and a task that takes
I'm building an application that needs to open self-signed HTTPS SSL URLs in java.
I'm building a java application that gets the mac addresses of a user and
I am currently building a java-servlet-based web application that should offer its service to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.