Я новичок Java искал способ сделать следующее:Сделайте что-нибудь, если требуется больше времени, чем х секунд продолжается со следующей задачей
- Чтение из файла CSV (CSVReader) одной линии в то время, ,
- Проделайте некоторый процесс с данными предыдущего шага.
- Если требуется более 30 секунд, пропустите процесс и перейдите к следующей строке.
У меня возникла проблема с шагом 3. Нужно ли устанавливать таймер для этого? Нужно ли мне играть с моей попыткой и поймать? Что вы предлагаете?
Это краткий мой код:
public static void main(String[] args) throws IOException, InterruptedException{
CsvReader data = new CsvReader("data.csv");
data.readHeaders();
int index = 1;
int index_max = 50;
int retry = 0;
int retry_max = 2;
while (index < index_max)
{
if (retry == 0)
{ data.readRecord();
String Column1 = data.get("COLUMN1");
String Column2 = data.get("COLUMN3");
String Column3 = data.get("COLUMN4");
...
}
else
{
//Retry with the same data
}
try {
//Invoke webservice to send the data and write on DB after validation
if (positive.answer == 0)
{
System.out.println("Great!!!");
index++;
retry = 0;
}
else
{
System.out.println("Bummer");
index++;
retry = 0;
}
}
catch (Exception e) {
if (e instanceof webservice_Exception){
//The Exception is about the webservice, print it
index++;
retry = 0;
} else {
//The Exception is about another thing, could be a transmission issue, please retry
retry++;
if (retry == retry_max)
{
retry = 0;
index++;
}
}
}
}
data.close();
}
Посмотрите здесь: http://stackoverflow.com/questions/2275443/how-to-timeout-a-thread –
Возможный дубликат [Как остановить выполнение через определенное время в Java?] (http://stackoverflow.com/questions/4252187/how-to-stop-execution-after-a-certain-time-in-java) –
Я предполагаю, что это CSV, а не CVS, правильно? – fge