activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oscar Pernas <os...@pernas.es>
Subject Re: AMQ-CMS - questions about threads/producerthreads in AMQ
Date Fri, 04 Mar 2011 11:26:34 GMT
I think that if you go to section CMS-API-Overview

http://activemq.apache.org/cms/cms-api-overview.html


 <http://activemq.apache.org/cms/example.html>At the end, you could see
something that is more addaptable for that you want. I think ;-)


regards

2011/3/4 <mzo@domdv.de>

> 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:
>
> Application:
>
> this->consumerThread = new Thread(&cmsConsAsync);
> this->consumerThread->start();
> cmsConsAsync.waitUntilReady();
> this->producerThread = new Thread(&cmsProdAsync);
> this->producerThread->start();
> cmsProdAsync.waitUntilReady();
> this->prodThreadID = this->producerThread->getId();
> printf("PID: %lld\n", this->prodThreadID);
> printf("State: %d\n", this->producerThread->getState());
> if (this->producerThread->isAlive())
>  {
>      printf("IsAlive\n");
>      kill(this->prodThreadID, SIGUSR1);
>      printf("IsAlive2\n");
>  }
>  else
>      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
>            latch.countDown();
>
>            //set to sleep, will wake up on signal calls
>            //waitLatch.await();
>            while(CMSProducer::noQuit)
>            {
>                printf("PAUSE!\n");
>                pause();
>            }
>
> Is there a better way to do something like this?
>
> Best regards,
> amqBeginner
>
>


-- 
Óscar Pernas Plaza.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message