How to kill a PacketCollector that is blocking by nextResult()?

Hello community, my first post…

I’m looking for a way to make a PacketCollector stop blocking after waiting on nextResult(). For example:

1 //some line before;
2 Packet packet = collector.nextResult();
3 //some line after;

How coluld I force PacketCollector to continue or throw an Exception or somthing when is blocked at line 2? I tried without luck with collector.clancel() and connection.close();

Maybe is not posible, should I use polling in that situation instead of blocking?

You could move it into a separate thread, which would allow you to wait or cancel it.

Thanks Op3racional. Yes, it’s done that way. The point is that its part of a servlet. In fact, nextResult() is implemented with a timeout of 2 minutes. I can operate all other things in other threads and its working fine. But when I want to shutdown the server, i have those threads waiting. The server dont wait so much and shutdowns abnormally. I was looking for a way to tell those threads to wait no more, so the server can go down normally. Am I missing something about Java threads here?

I don’t have much experience with multithreading in Java, but use a search engine:

http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html

You can also post a question about this on comp.lang.java.help (nntp).

I was looking at the source of smack an finally I think there is no way to kill a blocking PacketCollector.nextResult() method without hacking it a little bit.