public void run() {

        System.out.println("JobTracker Started");

		//Launch thread that will communicate with the clients.
		Thread clientThread = new Thread(new ClientHandler(this));
		clientThread.start();
		
		//set up loop to communicate with workers.
    	ServerSocket server = null;
    		
    	Socket clientSocket;
    	try {
    		server = new ServerSocket(workerCommPort);
    	} catch (Exception e) {
    		System.out.println("Cannot start job tracker. Quitting ...");
    		e.printStackTrace();
    		
    	}
    		
    	while(true) {
    		try {
	    		clientSocket = server.accept();
	    		ObjectInputStream ois = new ObjectInputStream(clientSocket.getInputStream());
				
	    		TaskTrackerHB taskTrackerHB = (TaskTrackerHB)ois.readObject();

	    		TaskTrackerHBResponse resp = handleHeartbeat(taskTrackerHB);
	    		
				ObjectOutputStream oos = new ObjectOutputStream(clientSocket.getOutputStream());
				oos.writeObject(resp);
				oos.flush();
				
				ois.close();
				oos.close();
				clientSocket.close();
				
				checkStaleHosts();
    		} catch (Exception e) {
    			e.printStackTrace();
    			try {
    				if(server != null) {
    					server.close();
    				}
    				server = new ServerSocket(workerCommPort);
    			} catch (Exception e2) {
    				e2.printStackTrace();
    			}
    		} 
    	}

	}