本文介绍了如何中断IMAP的IDLE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用连接到IMAP服务器的Javamail API. javax.mail.Folder.idle()方法.当收到一封新邮件时,我的侦听器将被调用.但是问题是永远空闲的块,如何中断它?如何实际上停止监听而不杀死Java程序?

I am using the Javamail API connecting to my IMAP server. Everything is working great with the javax.mail.Folder.idle() method. My listener gets called when a new mail comes in. However the problem is idle blocks forever, how do I interrupt it? How do I actually stop the listening without killing my Java program?

我尝试在空闲线程上调用Thread.interrupt().什么都没发生.我的想法不多了.

I've tried calling Thread.interrupt() on the idle'd thread. Nothing happens. I am running out of ideas.

推荐答案

对该文件夹执行任何操作(来自另一个线程)将导致idle()方法立即返回.因此,如果要强制中断它,只需从新线程中调用close().

Performing any operation on that folder (from another thread) will cause idle() method to return immediately. So if you want to forcefully interrupt it, just call close() from a new thread.

这篇关于如何中断IMAP的IDLE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 22:48