You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by Harmeet Bedi <hb...@yahoo.com> on 2001/03/16 04:30:33 UTC

potential thread problem in james/James.java

method <getId> in james/James.java. uses static variable <count> to create a
unique ID. The <count> is incremented per invoction of getId. One problem is
that increment of <count> is not atomic. So the method may not be thread
safe.

I think the implementation of <getId> could be made more thread safe by
making making count to be of type 'int', instead of 'long'
from:
---------------------------
    private static long count;
    public String getId() {
        return "Mail" + System.currentTimeMillis() + "-" + count++;
    }

to:
---------------------------
    private static int count;
    public String getId() {
        return "Mail" + System.currentTimeMillis() + "-" + count++;
    }

If this makes sense, could someone please commit it.

thanks,
Harmeet



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org