tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Schumacher <felix.schumac...@internetallee.de>
Subject Re: OT: help with concurrency issue
Date Sun, 21 Aug 2011 14:49:44 GMT


alexis <alzrck@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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message