当前位置:编程学习 > JAVA >>

一个非常离奇古怪的问题


if (isFirstInitialization) {
                packetWriter = new PacketWriter(this);
                packetReader = new PacketReader(this);

                // If debugging is enabled, we should start the thread that will listen for
                // all packets and then log them.
                if (config.isDebuggerEnabled()) {
                    addPacketListener(debugger.getReaderListener(), null);
                    if (debugger.getWriterListener() != null) {
                        addPacketSendingListener(debugger.getWriterListener(), null);
                    }
                }
            }
            else {
                packetWriter.init();
                packetReader.init();
            }

            // Start the packet writer. This will open a XMPP stream to the server
            packetWriter.startup();
            // Start the packet reader. The startup() method will block until we
            // get an opening stream packet back from server.
            packetReader.startup();

            // Make note of the fact that we're now connected.
            connected = true;

            // Start keep alive process (after TLS was negotiated - if available)
            packetWriter.startKeepAliveProcess();



Exception in thread "Thread-33" java.lang.NullPointerException
at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:595)
at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:548)
at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:974)
at net.sf.kraken.protocols.xmpp.XMPPSession$1.run(XMPPSession.java:277)
at java.lang.Thread.run(Thread.java:619)


// Start keep alive process (after TLS was negotiated - if available)
packetWriter.startKeepAliveProcess();

在这一行中出现了空指针错误,太古怪了.在这句代码之前,还有很多使用到packetWriter的地方呢,并且该对象是在上面被创建的.
这个问题并不是必现,只是当大并发的时候会出现,不知其原因,想请高手解答. --------------------编程问答-------------------- 你这个变量是局部变量还是?

有无可能在大并易做图况下,被其它线程给清理了? --------------------编程问答--------------------
引用 1 楼  的回复:
你这个变量是局部变量还是?

有无可能在大并易做图况下,被其它线程给清理了?

这是一个类变量.我想应该不会被其它线程给清理.
// Start keep alive process (after TLS was negotiated - if available)
packetWriter.startKeepAliveProcess();

因为每次都会到这一句才会出现null指针,而上面使用到的地方,也并没有修改packetWriter值的操作.
并且这个问题,一旦出现了之后,后面就一直会出现空指针.不会有成功的地方.

--------------------编程问答--------------------
补充:Java ,  Java SE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,