[concurrency-interest] ConcurrentHashMap NullPointerException

BJ Low notorand at gmail.com
Fri Jan 4 01:41:01 EST 2008


Hi,

What I have implemented is an NIO wrapper that is similar to Apache
MINA. In this, there are multiple n threads that is handling all the m
sockets reads/writes. However, it is guaranteed that only 1 thread can
notify the listener of each connections IO events. For example
Thread-1 notify listener onNewConnection(), and Thread-2 notify
listener onRead(), however Thread-1 and Thread-2 can never notify
concurrently, multithreaded underneath, but appears monothreaded

Right now, I am suspecting that it might be the case that Thread-1
when onNewConnection() constructs the key X and stores Y into the
ConcurrentHashMap, Thread-2 fails to see the key as initialized due to
Java Memory Model(even though Thread-2 executes after Thread-1),
resulting in null that is passed to CHM.get() and therefore resulting
in null return value

On Jan 4, 2008 1:58 PM, David Holmes <dcholmes at optusnet.com.au> wrote:
> BJ,
>
> Can you provide further information: code sketch, exception stack trace
> details. I'm unclear whether get() is returning null unexpectedly or whether
> get() is throwing the NPE. The usual source for the latter is misbehaving
> equals() methods.
>
> Cheers,
> David Holmes
>
>
> > -----Original Message-----
> > From: concurrency-interest-bounces at cs.oswego.edu
> > [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of BJ Low
> > Sent: Friday, 4 January 2008 3:08 PM
> > To: concurrency-interest at cs.oswego.edu
> > Subject: [concurrency-interest] ConcurrentHashMap NullPointerException
> >
> >
> > Hi all,
> >
> > I am seeing some bizarre behavior in the ConcurrentHashMap where one
> > thread constructs an objects and puts it into a the map and another
> > thread gets the object and sees it as null. Has any one encountered
> > this problem before. I believe this problem is posted sometime ago by
> > Eric Zoerner to this mailing list however there is no reply.
> >
> > Any help is greatly appreciated.
> >
> > --
> > Regards,
> > BJ Low
>
> > _______________________________________________
> > Concurrency-interest mailing list
> > Concurrency-interest at altair.cs.oswego.edu
> > http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
> >
>
>



-- 
Regards,
BJ Low


More information about the Concurrency-interest mailing list