better, concurrency issue is gone, facing a new one, i cannot stop the Consumer 
thread, i have this


 @Override
    public void run() {

        dao = (DAO) sc.getAttribute("dao");
        try {
            q = (Queue) sc.getAttribute("Queue");

            while (keepRunning) {
                Command c = q.get();
                    doExec dE = new doExec(c);
                    if (!dE.isAlive()) {
                        dE.start();
                        dE.join();
                    }
                Thread.sleep(1500);
            }

where keepRunning is a volatile boolean that i set to false when i try to end 
this Thread. so when i try to stop the consumer i call a method that sets the 
volatile to false, and then i call an interrupt. Resuming

to start

Consumer c = new Comsumer();
if(!c.isAlive())
c.start();


to stop

if(c.isAlive())
{
c.doStop(); //this turn keepRunning to false
c.interrupt();
while(c.isAlive())
{
log.info("Waiting for consumer to stop"); //now im facing a loop here, consumer 
never stops
}
}


On Aug 21, 2011, at 11:49 AM, Felix Schumacher wrote:

> 
> 
> alexis <alz...@gmail.com> schrieb:
> 
>> I marked this issue OT because i think is a conceptual issue and not
>> related to any application per se.
>> 
>> I have 2 main issues with concurrency, one class is a queue 
>> 
>> public class Queue {
>> 
>> private static org.apache.log4j.Logger log =
>> Logger.getLogger(Queue.class);
>>   private Command command;
>>   private boolean valueSet = false;
>> 
>>   public synchronized void put(Command c) {
>>       if (valueSet) {
> Try while instead of if.
>>           try {
>>               wait();
>>           } catch (InterruptedException ie) {
>>           }
>>       }
>>       this.command = c;
>> 
>>       log.info("put : "+c.getCommand());
>>       valueSet = true;
>>       notify();
>>   }
>> 
>>   public synchronized Command get() {
>>       if (!valueSet)  {
> Again, use while, not if.
>>           try {
>>               wait();
>>           } catch (InterruptedException ie) {
>>           }
>>       }
>>       valueSet = false;
>>       notify();
>> 
>>       log.info("get : "+this.command.getCommand());
>>       return command;
>>   }
>> }
>> 
>> 
> Regards
> Felix
>> Then i have 1 class that reads and execute the command property. only
>> one. Also, i have n classes trying constantly to "put" commands in the
>> queue. Usually it works ok, but i have situations like this
>> 
>> [xcall3] 2011-08-21 11:04:00,589  INFO Queue:39 - get : list trunk
>> [xcall3] 2011-08-21 11:04:00,589  INFO Queue:24 - put : list
>> agent-loginID
>> [xcall3] 2011-08-21 11:04:00,589  INFO Queue:24 - put : list bcms agent
>> 5116 day
>> 
>> 
>> list agent-loginID get lost and never is executed.
>> 
>> all clases trying to put uses the same code
>> 
>> new Producer(Queue q, Command c).start(); 
>> 
>> and 
>> 
>> public class Producer extends Thread {
>> 
>> private static org.apache.log4j.Logger log =
>> Logger.getLogger(Producer.class);
>>   private Queue q;
>>   private Command c;
>> 
>>   public Producer(Queue q, Command c) {
>>       this.q = q;
>>       this.c = c;
>>   }
>> 
>>   @Override
>>   public void run() {
>> 
>>       try {
>>           while (true) {
>>               q.put(c);
>>               break;
>>           }
>>       } catch (Exception e) {
>>           log.error(c.getCommand());
>>       } finally {
>>       }
>> 
>>   }
>> }
>> 
>> 
>> The second issue is, when the webapp is running, beside this problem,
>> everything goes ok, but when i call to stop the thread that "gets" from
>> queue, the last command is executed once again. So, the Consumer class,
>> reach a wait on get operation because there's no command to execute,
>> but when i interrupt this consumer class, get returns the last command
>> stored in the queue. a clue?
>> 
>> Thanks in advance.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to