Text file validation
<p>I am trying to validate some text files.  In the front end i am using JTextarea, The below method is called on every time the user enter 'Enter' key.  If the file is too big,say 5000 lines and if the user enters many times 'Enter' key then, i am getting unexpected results, like even if the line is valid, it shows it as invalid. </p>

<p>Is there any thing to do with sleep, should i have to increase the sleep time or something else has to be done?  Any ideas will be helpful</p>

<pre><code>private TreeSet validate(int curLine, TreeSet errorSet) {
    int increment = 0;
    int nextLine = 0;

    if (curLine == lines.length || errorSet.size() != 0) {
        return errorSet;
    } else {
        String line = lines[curLine];

        //validation starts.  After validation, line is incremented as per the requirements

         increment = 1 //As per requirement. Depends on validation results of the line



        if (increment &gt; 0) {
            try{
                 Thread.currentThread().sleep(100);  
               }catch(Exception ex){
                 System.out.println(ex); 
               }
            nextLine = (curLine + increment);
            validate(nextLine, errorSet);
        }
    }
    return errorSet;
}  
</code></pre>
