tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexis <>
Subject OT: help with concurrency issue
Date Sun, 21 Aug 2011 14:16:14 GMT
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 {
            } catch (InterruptedException ie) {
        this.command = c;
       "put : "+c.getCommand());
        valueSet = true;

    public synchronized Command get() {
        if (!valueSet) {
            try {
            } catch (InterruptedException ie) {
        valueSet = false;
        notify();"get : "+this.command.getCommand());
        return command;

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(); 


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;

    public void run() {

        try {
            while (true) {
        } catch (Exception e) {
        } 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.

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