一个非常离奇古怪的问题

fainfy 2012-09-04 05:25:54

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的地方呢,并且该对象是在上面被创建的.
这个问题并不是必现,只是当大并发的时候会出现,不知其原因,想请高手解答.
...全文
181 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fainfy 2012-09-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

你这个变量是局部变量还是?

有无可能在大并发情况下,被其它线程给清理了?
[/Quote]
这是一个类变量.我想应该不会被其它线程给清理.
// Start keep alive process (after TLS was negotiated - if available)
packetWriter.startKeepAliveProcess();

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

MiceRice 2012-09-04
  • 打赏
  • 举报
回复
你这个变量是局部变量还是?

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

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧