fellow programmers :-)
Is there a way to know if any thread is blocked on the specific semaphore (queue isn't empty), using win32 api and c++?
Thanks in advance :-)
How about waiting on the semaphore with at timeout? If the timeout fires, immediately lock the queue and check the count. This will only give a rough guide - it's posible for a producer to enqueue an object netween the timeout and locking the queue, but it might enable you to debug your P-C queue.
Related
Here is the following scenario. I have a Event Producer which publishes events. I referred the mircosoft document https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-java-get-started-send
According to my usecase, I have a bean which would create the eventhubProducerClient connection at start of my application. However , the producer.close() in my send method (from above documentation) is called after each event is sent. So, this leads to close of my producer and when I would like to send the next event, there is already an exception that the producer is terminated.
What is the best way to handle the producer.close (). can I leave the producer open ? Wouldnt that cause a memory leak ? Is there a strategy on how I can handle this ?
any lead would be helpful
thank you
Each of the Event Hubs client types is safe to cache and use as a singleton for the lifetime of the application, which is best practice when events are being published or read regularly. The clients are responsible for efficient management of network, CPU, and memory use, working to keep usage low during periods of inactivity. Calling close on a client is required to ensure that network resources and other unmanaged objects are properly cleaned up.
I am using an FTP client in a seperate thread. The FTP client uses a job list to up-/download files to a connected server. If the thread wants to communicate with my main thread it will use an event queue. The thread will create an event, put it into the queue and then post a windows message to my main thread telling me that there are new events in the queue.
The main thread then fetches the latest event from the queue and removes it. The queue is held in the thread object but I am using a lock to make it thread-safe.
I created a function within my main thread which is listening for messages from the FTP thread. I also registered a handle for this method (via AllocateHwnd()) so that the thread is posting it's messages excactly to the listening method of my main thread.
Now I want to know if the following scenario is possible:
I destroy the thread. Right before it gets destroyed the thread will post a windows message to the main thread because there is a new event. The windows message however has some delay (for whatever reason). Now the thread gets destroyed and the thread object is gone. Of course, the event queue is also gone. The main thread now receives the delayed windows message telling him that there is a new event in the queue. It tries to fetch the queue which will result in an invalid pointer operation since there the queue and the thread object have been free'd.
To avoid this problem, I implemented a check into my message listening method. Right before I access the event queue from the thread I will check if the thread still exists. If yes, then I access the event queue, if no, then I will simply drop the message.
However, what if the thread gets destroyed right after I checked it, but before I access the queue. The sequence would be like this:
Check if thread exists
(thread gets destroyed NOW)
Access event queue
Can this scenario still happen? I know that this does sound like a very specific and tiny scenario since the thread would have to get destroyed right between those two commands in order to fail but I want to make sure that I do not access the event queue when the thread is actually not existing anymore.
I hope I could explain my problem well enough. Thanks in advance for any provided answers.
We are using IBM MQ and we are facing some serious problems regarding controlling its asynchronous delivery to its recipient.We are having some java listeners configured, now the problem is that we need to control the messages coming towards listener, because the messages coming to server are in millions count and server machine dont have that much capacity t process so many threads at a time, so is there any way like throttling on IBM MQ side where we can configure preetch limit like Apache MQ does?
or is there any other way to achieve this?
Currently we are closing connection with IBM MQ when some X limit has reached on listener, but doesen't seems to be efficient way.
Please guys help us out to solve this issue.
Generally with message queueing technologies like MQ the point of the queue is that the sender is decoupled from the receiver. If you're having trouble with message volumes then the answer is to let them queue up on the receiver queue and process them as best you can, not to throttle the sender.
The obvious answer is to limit the maximum number of threads that your listeners are allowed to take up. I'm assuming you're using some sort of MQ threadpool? What platform are you using that provides unlimited listener threads?
From your description, it almost sounds like you have some process running that - as soon as it detects a message in the queue - it reads the message, starts up a new thread and goes back and looks at the queue again. This is the WRONG approach.
You should have a defined number of process threads running (start with one and scale up as required, and within limits of your server) which read from the queue themselves. They would each open the queue in shared mode and either get-with-wait or do immediate get with a sleep if you get a MQRC 2033 (no messages in queue).
Hope that helps.
If you are running in the application server environment, then the maxPoolDepth property on the activationSpec will define the maximum ServerSessionPool size for the MDB - decreasing this will throttle the number messages being delivered concurrently.
Of course, if your MDB (or javax.jms.MessageListener in the JSE environment) does nothing but hand the message to something else (or, worse, just spawn an unmanaged Thread and start it) onMessage will spin rapidly and you can still encounter problems. So in that case you need to limit other resources too, e.g. via threadpool configuration.
Closing the connection to the QM is never an efficient way, as the MQCONN/MQDISC cycle is expensive.
I have a simple program to process messages from a queue.
My intention is to process all available messages in queue and still listen to queue for incoming messages.
I have written the processing part inside a infinite loop as i want it to listen to queue always and process messages.
Once after processing all messages again it tries to get a message(as it is inside a infinite loop) from the queue and there
is no messages it throws MQRC 2033 NO_MSG_AVAILABLE exception(infact it is correct) and my program exits.
Can someone give an idea to continously listen to this queue and avoid this exception.
When you execute the MQGET API call, there is an option to have the program wait for messages. You can specify a wait time (in milliseconds) or specify to wait forever. Just make sure that if you have the app wait for more than a few seconds, also specify 'Fail if Quiescing'. This allows the queue manager to be stopped cleanly. Without 'Fail if Quiescing' the administrator will need to issue a preemptive shutdown which can cause problems.
There is a section specifically for this question in the Programmer's Guide in the Waiting for Messages chapter. Depending on the language you are writing in ,the actual value to specify is in the Programmer's Reference, the Using Java manual or the Using .Net manual. Each of these will be visible in the navigation panel when you click the link above.
I have an application which tries to subscribes to a lot of different topics.
The server side publishes a lot of messages through these topics and as soon as the application starts subscribing, it receives so many messages that the application cannot even reach the end of the subscription function.
It seems that the OnMessage Listener is flooded so much (the listener is the class which is trying to subscribe itself ot all the topics).
So basically is there a way to stop the reception of messages until I have subscribed to all of the topics? Or am I missing something there?
The thread trying to subsscribe to all of the topics never get the processor again.
(If the server is down, the subscription is fine since it does not receive anything so it does not lose the processing power..)
Thank you in advance.
Paul.
You could try lower the prefetch limit of the consumers, this would prevent the broker from attempting to dispatch so many messages when they are created which should help reduce the flooding issue you are seeing.
Here's some documentation that might help.
http://activemq.apache.org/what-is-the-prefetch-limit-for.html
Tim -
www.fusesource.com