public static void main(String[] args) { new ServerThread().start accept input from the console }
if (serverThread == null || !serverThread.isAlive()) { ServerThread st=new ServerThread(s); st.start(); } else s.close();
private void shutdownServerThread() { shuttingDown = true; closeServerSocket(); interrupt(); try { join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }
Socket clientSocket = serverSocket.accept(); ServerThread serverThread; if (portNumber == Server.SMTP_PORT_NUMBER) { serverThread = new SMTPThread(clientSocket, db); serverThread.setName("SMTP Thread " + ++threadCounter); } else { serverThread = new POP3Thread(clientSocket, db); serverThread.setName("POP3 Thread " + ++threadCounter); } serverThread.start(); threadPool.put(serverThread);
ServerThread st = new ServerThread(); new Thread(st).start(); st.myMethod();
/** * Call this method to get things rolling after instantiating the * SMTPServer. */ public synchronized void start() { if (log.isInfoEnabled()) log.info("SMTP server {} starting", getDisplayableLocalSocketAddress()); if (this.started) throw new IllegalStateException( "SMTPServer can only be started once"); // Create our server socket here. ServerSocket serverSocket; try { serverSocket = this.createServerSocket(); } catch (Exception e) { throw new RuntimeException(e); } this.serverThread = new ServerThread(this, serverSocket); this.serverThread.start(); this.started = true; }
ServerThread st= new ServerThread(s); sSocketList.add(s); sObjectList.add(st); st.start(); i.calculatePos();
this.serverThread.getNumberOfConnections()); serverThread.sessionEnded(this); Thread.currentThread().setName(originalName); MDC.clear();
// Keep the server thread as a variable, so we can check if it's already connected. ServerThread serverThread = null; while (true) { try { socket = serverSocket.accept(); Status = ("Connecting accepted"); if (serverThread == null || !serverThread.isAlive()) { // No other client is connected, so start a new thread. serverThread = new ServerThread(socket); serverThread.start(); System.out.println("Client connected.") } else { // A client is already connected, so close the socket. socket.close(); System.out.println("Client already connected: connection closed.") } } catch (Exception e) { e.printStackTrace(); System.out.println("Connection Error"); } }
/** * Shut things down gracefully. */ public synchronized void stop() { if (log.isInfoEnabled()) log.info("SMTP server {} stopping", getDisplayableLocalSocketAddress()); if (this.serverThread == null) return; this.serverThread.shutdown(); this.serverThread = null; }
/** * This method is called by this thread when it starts up. To safely cause * this to exit, call {@link #shutdown()}. */ @Override public void run() { MDC.put("smtpServerLocalSocketAddress", server.getDisplayableLocalSocketAddress()); log.info("SMTP server {} started", server.getDisplayableLocalSocketAddress()); try { runAcceptLoop(); log.info("SMTP server {} stopped accepting connections", server.getDisplayableLocalSocketAddress()); } catch (RuntimeException e) { log.error("Unexpected exception in server socket thread, server is stopped", e); throw e; } catch (Error e) { log.error("Unexpected error in server socket thread, server is stopped", e); throw e; } finally { MDC.remove("smtpServerLocalSocketAddress"); } }
if (this.serverThread.hasTooManyConnections())
/** * Call this method to get things rolling after instantiating the * SMTPServer. * <p> * An SMTPServer which has been shut down, must not be reused. */ public synchronized void start() { if (log.isInfoEnabled()) log.info("SMTP server {} starting", getDisplayableLocalSocketAddress()); if (this.started) throw new IllegalStateException( "SMTPServer can only be started once. " + "Restarting is not allowed even after a proper shutdown."); // Create our server socket here. ServerSocket serverSocket; try { serverSocket = this.createServerSocket(); } catch (Exception e) { throw new RuntimeException(e); } this.serverThread = new ServerThread(this, serverSocket); this.serverThread.start(); this.started = true; }
this.serverThread.getNumberOfConnections()); serverThread.sessionEnded(this); Thread.currentThread().setName(originalName); MDC.clear();
/** * Shut things down gracefully. */ public synchronized void stop() { log.info("SMTP server {} stopping...", getDisplayableLocalSocketAddress()); if (this.serverThread == null) return; this.serverThread.shutdown(); this.serverThread = null; log.info("SMTP server {} stopped", getDisplayableLocalSocketAddress()); }
/** * This method is called by this thread when it starts up. To safely cause * this to exit, call {@link #shutdown()}. */ @Override public void run() { MDC.put("smtpServerLocalSocketAddress", server.getDisplayableLocalSocketAddress()); log.info("SMTP server {} started", server.getDisplayableLocalSocketAddress()); try { runAcceptLoop(); log.info("SMTP server {} stopped", server.getDisplayableLocalSocketAddress()); } catch (RuntimeException e) { log.error("Unexpected exception in server socket thread, server is stopped", e); throw e; } catch (Error e) { log.error("Unexpected error in server socket thread, server is stopped", e); throw e; } finally { MDC.remove("smtpServerLocalSocketAddress"); } }
if (this.serverThread.hasTooManyConnections())
System.out.println("Waiting for connection"); Socket socket = server.accept(); ServerThread connection = new ServerThread(socket, this); System.out.println("New client connected"); System.out.println("----------------------------------"); connection.start();
ServerThread serverthread = new ServerThread(); Thread t = new Thread(serverthread);
private void shutdownServerThread() { shuttingDown = true; closeServerSocket(); interrupt(); try { join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }