|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Nov 2004
Messaggi: 691
|
[JAVA] Thread sparito nel nulla (no exceptions)
Posto prima il codice:
Codice:
long length = file.length();
while (true) {
if (length <= file.length()){
if ((line = input.readLine()) != null)
new myObject(line, dbM);
if (file.length() >= length)
length = file.length();
continue;
} else {
fs.close();
fileReader.close();
input.close();
file = new File(log);
fs = new FileInputStream(log);
fileReader = new InputStreamReader(fs);
input = new BufferedReader(fileReader);
length = file.length();
System.out.print("["+Utilities.getDate() + "] ");
System.out.println("["+Thread.currentThread().getName() + "] recreated [" +log+ "].");
}
try {
Thread.sleep(1000L);
//... if it's 2 am
System.out.print("["+Utilities.getDate() + "] ");
System.out.print("["+Thread.currentThread().getName() + "] ");
System.out.println("is alive.");
} catch (InterruptedException x) {
}
}
Una vulnerabilità sarebbe se la cat/dev null viene lanciata mentre il flusso di esecuzione è tra Codice:
if (file.length() >= length) Codice:
length = file.length(); Questa mattina, dopo che tutto ha funzionato senza problemi per un bel po', ho notato nel log che la System.out del blocco else era stata stampata, e la rotazione è andata a buon fine come sempre, tuttavia verso l'1 del mattino il thread si è apparentemente appeso, dato che non è più partita la System.out del blocco try. myObject inserisce la linea letta in un DB, e farebbe crashare tutto se l'inserimento dovesse fallire (come è gia capitato per problemi di rete etc) Cosa potrebbe essere successo al mio thread? Ringrazio tutti come sempre, TD |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Nov 2004
Messaggi: 691
|
uppino...
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Jul 2006
Città: Bergamo
Messaggi: 401
|
Prova ad aggiungere la stampa quando catchi l'eccezione e vedi se ti stampa qualcosa oppure fa tutto come prima...
__________________
iMac 27" 5K |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Nov 2004
Messaggi: 691
|
E' vero non ho copiato parte del codice per sintetizzare e non spaventare con un muro di codice, il resto è:
Codice:
} catch (InterruptedException x) {
System.out.print(Utilities.getDate() + " ");
System.out.println(Thread.currentThread().getName() + " interrupted.");
x.printStackTrace();
Thread.currentThread().interrupt();
}
} // -> chiude il while(true)
} catch(Exception e){
System.out.print(Utilities.getDate() + " ");
System.out.println("Failure to run the run() method of "+Thread.currentThread().getName());
e.printStackTrace();
Thread.currentThread().interrupt();
}
Codice:
try{
Thread.sleep()
}
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Nov 2004
Messaggi: 691
|
uppino x 2
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 00:12.



















