Basically, i need to parse an XML file, put it into an ArrayList of class objects, and pass this (as well as a socket) to a thread. This thread will then do some functionality with the given ArrayList, and pass the result back to the socket. My problem is, I am not able to pass the parsed data in the form of an ArrayList to the thread.
Here is some code:
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null;
boolean listening = true;
/*xml parsing is done, result is saved in ArrayList<class> peds*/
try {
serverSocket = new ServerSocket(4444);
} catch (IOException e) {
System.err.println("Could not listen on port: 4444." + e);
System.exit(-1);
}
while (listening){
Socket s = serverSocket.accept();
Runnable proExec = new KKMultiServerThread( s, peds); **
Thread th = new Thread (proExec)
th.start(); }
serverSocket.close();
}
class KKMultiServerThread implements Runnable{
private Socket socket = null;
public final ArrayList<show> peds;
public KKMultiServerThread(Socket socket, ArrayList<show> peds) {
this.socket = socket;
this.peds = peds;
}
** The problem is occurring in this line. Says :non-static variable cannot be referenced from a static context.
have tried all possible combinations (such as placing the runnable class in another file, and calling a function to return the data structure.. the IDE does not allow me to do this.)
seems like the only possible remaining solution to this problem is to parse the xml file and save it in a data structure FOR EACH THREAD... this seems too costly to be efficient.
please help!