activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject AMQ-CMS - questions about threads/producerthreads in AMQ
Date Fri, 04 Mar 2011 11:19:17 GMT
Hello there,

greetings from Germany. ;)

I'm currently trying to work myself into AMQ. I already tried several
approches to the producer thread question and have searched the web and the
forum. I'm also a beginner to the multithreading theme.

The situation:
I would like my application to create a consumer and a producer, which is no
problem. But both should live forever.
The consumer sleeps via a Countdownlatch, which will never be count down,
and wakes up via a Messagelistener, when a message is recieved.
The producer is my main problem. The application tells me to send a message.
Now i want to tell my producer thread to send this message syncron with
failure handling etc, while my application runs on. How do i tell the thread
to wait for a message? How do I tell the threads to live forever?

I already thought about using mutexes, semaphores, signals etc. But i found
out that the decaf threads already use pthread internally. So i guess there
exists functions for my problems, that i haven't found so far.

Propably my first trys do something which is way to complex, where there
already exists methods or wrapper:

I already tried to use signals, but the signal doesn't seems work with the
threadID i get from the decaf thread. Eg:


this->consumerThread = new Thread(&cmsConsAsync);
this->producerThread = new Thread(&cmsProdAsync);
this->prodThreadID = this->producerThread->getId();
printf("PID: %lld\n", this->prodThreadID);
printf("State: %d\n", this->producerThread->getState());
if (this->producerThread->isAlive())
      kill(this->prodThreadID, SIGUSR1);
      printf("I'm killed!\n");

The Producer:

            /* set function calls */
            signal(SIGUSR1, CMSProducer::sendTextMessage);
            signal(SIGUSR2, CMSProducer::sendObjMessage);
            signal(SIGQUIT, CMSProducer::shutdown);

            //let caller run on

            //set to sleep, will wake up on signal calls

Is there a better way to do something like this?

Best regards,

View raw message