I'm creating a program that can read .log files in certain directories and then dumps the data from the .log files into a local database.
However, i noticed in my testing that whenever the program reads the files and i happen to access the files during the test run - the program freezes.
How do i solve this issue?
public static void file(File[] files)
{
try
{
for (File lister : files)
{
System.out.println("HERE " + lister);
in = new FileReader(lister);
br = new BufferedReader(in);
try
{
while ((sCurrentLine = br.readLine()) != null)
{
if (sCurrentLine.contains("Performance"))
{
String[] aCurrentLine = sCurrentLine.split("\\|");
if (aCurrentLine.length >= 6) {
Date date = dateinsert.parse(aCurrentLine[0]);
CurrentTime = dateinsert.format(date);
CurrentFlow = aCurrentLine[2];
CurrentModule = aCurrentLine[5];
CurrentType = aCurrentLine[4];
sCurrentID = aCurrentLine[6];
aCurrentLine = aCurrentLine[6].split("ORDER_ID");
if (aCurrentLine.length >= 2)
{
aCurrentLine[1] = aCurrentLine[1].replace (":", "");
aCurrentLine[1] = aCurrentLine[1].replace (" ", "");
aCurrentLine[1] = aCurrentLine[1].replace ("_", "");
aCurrentLine[1] = aCurrentLine[1].replace ("{", "");
aCurrentLine[1] = aCurrentLine[1].replace ("}", "");
aCurrentLine = aCurrentLine[1].split ("\"");
sCurrentID = aCurrentLine[2];
}
else // Happens when there's no order id
{
sCurrentID = "N/A";
}
cal = Calendar.getInstance();
year = cal.get(Calendar.YEAR);
month = cal.get(Calendar.MONTH);
datenum = cal.get(Calendar.DAY_OF_MONTH);
hour = cal.get(Calendar.HOUR_OF_DAY);
minute = cal.get(Calendar.MINUTE);
second = cal.get(Calendar.SECOND);
if (month<9)
{
month = month + 1;
smonth = "0" + Integer.toString(month);
}
else
{
month = month + 1;
smonth = Integer.toString(month);
}
if (datenum<10)
{
sdatenum = "0" + Integer.toString(datenum);
}
else
{
sdatenum = Integer.toString(datenum);
}
if (hour<10)
{
shour = "0" + Integer.toString(hour);
}
else
{
shour = Integer.toString(hour);
}
if (minute<10)
{
sminute = "0" + Integer.toString(minute);
}
else
{
sminute = Integer.toString(minute);
}
if (second<10)
{
ssecond = "0" + Integer.toString(second);
}
else
{
ssecond = Integer.toString(second);
}
scalendar = Integer.toString(year) + "-" + smonth + "-" + sdatenum + " " + shour + ":" + sminute+ ":" + ssecond;
ls.insertdata(sCurrentID, CurrentTime, CurrentFlow, CurrentModule, CurrentType, scalendar);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
flag = 0;
}
}