@Override
    public void run(){
        isAlive = true;
        try{
            PrintWriter printWriter = new PrintWriter(socket.getOutputStream());
            while(isAlive){
                synchronized (messageList){
                    while(!messageList.isEmpty()){
                        printWriter.println(messageList.remove(0));
                        printWriter.flush();
                    }

                    messageList.wait();
                }
            }
        } catch (Exception e){
            e.printStackTrace();
        } finally {
            isAlive = false;
            try{
                socket.close();
            } catch (IOException e){
                e.printStackTrace();
            }
        }
    }