Can you help me with this code, I do not know what is wrong? Thread is stuck somewhere?
import java.io.*;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
public class Pokemon
{
private static ArrayList<String> pokemonList = new ArrayList<String>();
private static ArrayList<Thread> threads = new ArrayList<Thread>();
private static ReentrantLock lock = new ReentrantLock();
public Pokemon()
{
int k =1;
while(true)
{
String file = "PokeRecord_"+k+".dat";
File newFile = new File(file);
if(newFile.exists())
{
try{
Thread runLab = new Thread(new PlayMe(newFile));
runLab.start();
threads.add(runLab);
Thread.sleep(50);
}
catch (InterruptedException ioe){}
}
else
{
//System.exit(0);
//false;
break;
}
k++;
}
for (int i = 0; i < threads.size(); i++) {
try {
threads.get(i).join();
}
catch (InterruptedException ignore) {}
}
System.out.printf("Loaded list size has %,8d Pokemnos.%n", pokemonList.size());
}
public class PlayMe implements Runnable
{
private File newFile;
private String name;
private long sightings;
public PlayMe(File newFile)
{
this.newFile = newFile;
}
public void run()
{
try{
FileInputStream fis = new FileInputStream(newFile);
DataInputStream dis = new DataInputStream(fis);
while (true)
{
try{
name = dis.readUTF();
sightings = dis.readLong();
//System.out.println(name);
lock.lock();
pokemonList.add(name);
lock.unlock();
}
catch (IOException e3of){ //System.err.println("End of File" + eof);
}
}
}
catch (FileNotFoundException fnf){ //System.err.println("End of File" + eof);
}
}
}
public static void main(String[] args) {
new Pokemon();
if(args.length > 0)
{
for (String a: args)
{
int sight = pokemonList.indexOf(a);
// not found
if(sight == -1)
{
System.out.printf("\n%-17s NO POKEMON", a);
System.exit(0);
}
// found
else
{
System.out.printf("\n%-17s was seen %8s times", a, sight);
System.exit(0);
}
System.out.println(" was NOT found");
}
}
else
{
System.exit(0);
}
}
}