Boa tarde pessoal, estou migrando do vb para o Java.
Estou com dúvidas quanto ao tratamento de erro de uma thread sendo executada.
Preciso que mesmo que seja gerado um erro a thread continue sendo executada, tipo um on error resume next do vb6
Outra duvida: melhor o while(true) dentro do try ou fora?
Algum colega poderia me ajudar com isso?
public void run() {
try{
while(true){
this.selector.select();
Set<SelectionKey> selectedKeys = this.selector.selectedKeys();
Iterator<SelectionKey> it = selectedKeys.iterator();
while(it.hasNext()){
SelectionKey key = it.next();
it.remove();
if (!key.isValid()) {
continue;
}
if (key.isConnectable()) {
SocketChannel keyChannel = (SocketChannel) key.channel();
if (keyChannel.isConnectionPending()) {
keyChannel.finishConnect();
}
}
if(key.isAcceptable()){
accept(key);
} else if(key.isReadable()){
read(key);
} else if (key.isWritable()) {
write(key);
}
}
}
} catch(Exception a){
Util.logError("ERRO RUN - " + a.getMessage() + " " + a.toString());
}
}
Luciano
Responder através da web | através de email | Adicionar um novo tópico | Mensagens neste tópico (2) |
Para upload/download de arquivos: http://www.yahoogroups.com/files/java-br
0 comentários:
Postar um comentário