public void run() {
        try {
            // Reading port from parameters.
            int port = parameters.getPort();
            // Reading IP from parameters.
            InetAddress ip = parameters.getIP();
            // Initialising cache.
            ICache cache = new Cache(parameters, new SaveLoadCache());
            // Loading cache from file that is defined in parameters.
            log.debug("Initializing thread factory.");
            CalculationThreadFactory factory = new CalculationThreadFactory(parameters);
            log.debug("Initializing socket.");
            Socket socket = new Socket();
            try {
                log.debug("Initializing server socket using values from parameters.");
                serverSocket = new ServerSocket(port, BACKLOG, ip);
                ServerUserInterface.sendMessageToConsole(InterfaceMessages.SERVER_IS_STARTED_MESSAGE.toString() + port + ".", false);
                log.debug("Starting endless cycle of connections.");
                serverSocket.setSoTimeout(SOCKET_TIMEOUT);
                while (isTurnedOn) {
                    try {
                        socket = serverSocket.accept();
                        if (isTurnedOn) {
                            log.debug("Connection accepted.");
                            log.debug("Creating thread for calculation.");
                            factory.createThread(socket, cache);
                        }
                    } catch (SocketTimeoutException ignored) { //Every SOCKET_TIMEOUT milliseconds server checks if it is turned on.
                    }
                }
                factory.shutDownFactory();
            } catch (IOException e) {
                ServerUserInterface.sendMessageToConsole(InterfaceMessages.EXCEPTION_MESSAGE.toString() + e, false);
                log.error("Error in accepting connection.");
            } finally {
                try {
                    log.debug("Closing socket.");
                    socket.close();
                    log.debug("Socket clothed successfully.");
                    log.debug("Closing server socket.");
                    serverSocket.close();
                    log.debug("Server socket clothed successfully.");
                } catch (Exception e) {
                    log.error("Socket closing error.");
                }
            }
        } catch (Exception e) {
            // Catching all unexpected exceptions in this thread.
            log.error("Unexpected exception", e);
        }
    }