使用空闲管理器会出现此异常: 线程“main”中的异常javax.mail.MessagingException:文件夹未使用SocketChannels
我该如何解决这个问题?
ExecutorService es = Executors.newCachedThreadPool();
final IdleManager idleManager = new IdleManager(session, es);
folder.open(Folder.READ_WRITE);
folder.addMessageCountListener(new MessageCountAdapter() {
public void messagesAdded(MessageCountEvent ev) {
Folder folder = (Folder)ev.getSource();
Message[] msgs = ev.getMessages();
System.out.println("Folder: " + folder +
" got " + msgs.length + " new messages");
try {
// process new messages
System.out.println("***********************process new messages : ");
idleManager.watch(folder); // keep watching for new messages
} catch (IOException | MessagingException ex) {
Logger.getLogger(mail2.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
idleManager.watch(folder);
答案 0 :(得分:2)
正如IdleManager javadocs所说:
..在Session
中设置mail.imap.usesocketchannels属性
答案 1 :(得分:0)
public void watch_mail(Folder folder) throws IOException, MessagingException, InterruptedException {
Thread t = new Thread(new Runnable() {
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
System.out.println("hi, interrupted = " + Thread.currentThread().isInterrupted());
folder.getMessageCount();
idleManager.watch(folder);
Thread.currentThread().sleep(30000);
} catch (MessagingException | InterruptedException | IOException ex) {
Logger.getLogger(listening_test.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
folder.addMessageCountListener(new MessageCountAdapter() {
public void messagesAdded(MessageCountEvent ev) {
Folder folder = (Folder) ev.getSource();
Message[] msgs = ev.getMessages();
System.out.println("Folder: " + folder
+ " got " + msgs.length + " new messages");
for (int i = 0; i < msgs.length; i++) {
try {
// Get dates date 1 (day_month_year) and date 2(hours:min:second)
String dates[] = getDates(msgs[i]);
System.out.println("*************date 1: " + dates[0]);
System.out.println("*************date 2: " + dates[1]);
idleManager.watch(folder);
} catch (ParseException | MessagingException | IOException ex) {
Logger.getLogger(listening_test.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
t.start();
}
hi, interrupted = false
DEBUG IMAP: IdleManager watching INBOX
A4 IDLE
+ idling
DEBUG IMAP: IdleManager selected 0 channels
DEBUG IMAP: IdleManager adding INBOX to selector
DEBUG IMAP: IdleManager waiting...
hi, interrupted = false
DEBUG IMAP: IdleManager selected 0 channels