aiuto sono disperato... sto modificando un server ftp free preso dal web...
ho dei problemi relativi alla memoria...
ogni utente che si connette al server ftp avvia un thread e da takmanager ho notato che la memoria umenta di 300 k..
Quando però l'utente si disconnette mi scende di solo 100 k !!!!
aiutatemi sono disperatooooo !!!!!!!!![]()
![]()
questa è la parte di codice relativa all'avvio del thread...
codice:package server.services; import it.vegaspa.clientFXS.businessLogic.MailHelper; import java.net.*; import java.io.*; import java.util.*; import server.*; import server.event.*; public class Dock implements Runnable{ private long sessionNr = Conf.getSession(); private Thread th; private ServerSocket ss; private static BigBrother bb = BigBrother.getInstance(); private int maxConnections = Conf.getMaxUsers(); private HashSet probes = new HashSet(); private static HashMap users = new HashMap(); private HashSet obs; private boolean suspended=false; private boolean autoSave=false; public Dock( HashSet observers ){ obs = observers; } //off as default public void setAutoSave(boolean on) { autoSave = on; } public boolean doesAutoSave() { return autoSave; } public void start(){ suspended=false; th = new Thread(this); th.start(); } public boolean stop(){ suspended=true; try{ if (ss != null) ss.close(); ss = null; return true; }catch(IOException e){ bb.dockException(e,"Could not stop the server."); return false; } } public boolean isRunning() { if (ss == null) return false; return !ss.isClosed(); } public synchronized void run(){ Socket socket; // IMPOSTO INDIRIZZO IP DI DEFAULT String indirizzoIP = ""; try{ // LETTURA DA FILE DI CONFIGURAZIONE DELL'INDIRIZZO IP (se vuoto utilizzo quello locale) indirizzoIP = Conf.getNodeValue("Server.ip"); if (indirizzoIP.equals("")){ indirizzoIP = java.net.InetAddress.getLocalHost().getHostAddress(); } ss = new ServerSocket(Conf.getServerPort(),100, InetAddress.getByName(indirizzoIP)); obsServerStarted(true); while(true){ // PULIZIA DELLA MEMORIA System.gc(); socket = ss.accept(); if (!Conf.isBanned(socket) && probes.size() < maxConnections) { // CONTROLLO LIMITE SESSIONE if (sessionNr >= 2147483647){ sessionNr = 0; } Probe p = new Probe(socket, this, sessionNr++); probes.add(p); obsClientConnected(p.ses.us); p.start(); Conf.setSession(sessionNr); }else { socket.close(); } } }catch(SocketException se) { if (!suspended){ obsServerStarted(false); //server could not be started // SERVER NON AVVIATO arrestaProgramma(indirizzoIP, Conf.getServerPort() ); } }catch(IOException e){ bb.dockException(e,""); } catch (Exception e) { // SERVER NON AVVIATO if(indirizzoIP.equals("")){ indirizzoIP = "unknown"; } arrestaProgramma(indirizzoIP, Conf.getServerPort() ); } if(suspended) obsServerStoped(); } public static void userLogedOut(Session ses) { /* String key = ses.getLogin() + ses.clientCommandSocket.getInetAddress().getHostAddress(); int i = Integer.parseInt(users.get(key).toString()); users.put(key,""+(--i)); */ } public void disconnect(Probe p) { String login = p.ses.getLogin(); if (p.ses.logedIn && !login.equals("")) { p.ses.logFile.stop(); userLogedOut(p.ses); } probes.remove(p); //Opdaterer observers obsClientDisconnected(p.ses.us); //if (autoSave) //Conf.save(); } public static boolean canUserLogin(Session ses) { String key = ses.getLogin() + ses.clientCommandSocket.getInetAddress().getHostAddress(); Object o = users.get(key); int now; if (o == null) { now = 0; }else { now = Integer.parseInt(o.toString()); } String mls = Conf.getUserOption(ses.xml,"max_logins_per_user"); int mli=-1; if (!mls.equals("")) { try { mli=Integer.parseInt(mls); }catch(NumberFormatException nfe) { ses.bb.commandoException(nfe, "The value ["+mls+"] i max_logins at the user: " + ses.getLogin() + " were not a number. no limits is set."); } } if (mli > now || mli < 0) { users.put(key, ""+(++now)); return true; }else return false; } public HashSet getUsers() { return probes; } public synchronized int getServerPort() { if (ss==null) { return Conf.getServerPort(); }else { return ss.getLocalPort(); } } private void obsClientConnected(UserSession us) { Iterator i = obs.iterator(); while (i.hasNext()) { ((ServerObserver)i.next()).clientConnected(us); } } private void obsClientDisconnected(UserSession us) { Iterator i = obs.iterator(); while (i.hasNext()) { ((ServerObserver)i.next()).clientDisconnected(us); } } private void obsServerStarted(boolean startOk) { Iterator i = obs.iterator(); while (i.hasNext()) { ((ServerObserver)i.next()).serverStarted(startOk); } } private void obsServerStoped() { Iterator i = obs.iterator(); while (i.hasNext()) { ((ServerObserver)i.next()).serverStoped(); } } /** * FUNZIONE PER IL BLOCCO DEL PROGRAMMA E AVVISO TRAMITE MAIL * */ private void arrestaProgramma(String indirizzo, int porta) { Conf conf = Conf.getInstance(); // INIZIALIZZO VARIABILI String mail_from = ""; String mail_to = ""; String mail_tentativi_s = "3"; String mail_wait_time_s = "60000"; int mail_tentativi = 3; long mail_wait_time = 300000; // CARICO DA CONFIGURAZIONE LE VARIABILI x INVIO MAIL try{ mail_from = conf.getNodeValue("Mail_Err.mail_from"); mail_to = conf.getNodeValue("Mail_Err.mail_to"); mail_tentativi_s = conf.getNodeValue("Mail_Err.mail_tentativi"); mail_wait_time_s = conf.getNodeValue("Mail_Err.mail_wait_time"); } catch (Exception e) { } // CONTROLLI CAMPI E CORREZIONI try{ mail_tentativi = Integer.parseInt(mail_tentativi_s); mail_wait_time = Long.parseLong(mail_wait_time_s); } catch (Exception e) { } int esecuzioneProcedura = mail_tentativi; // CONTROLLO SE NON HO UTENTI VALIDI IMPOSTO DEFAULT if(mail_from.equalsIgnoreCase("")){ mail_from = "network.management@vegaspa.it"; } if(mail_to.equalsIgnoreCase("")){ mail_to = "network.management@vegaspa.it"; } MailHelper mailHelper = new MailHelper(mail_from); boolean mailInviata = false; // CICLO INFINITO PER INVIO MAIL while (esecuzioneProcedura > 0){ // MAIL AMMINISTRATORE AVVISO ERRORE String oggettoMail = "ERRORE AVVIO SERVER FTP-MQ"; String testoMail = "Non è stato possibile avviare il server Ftp-MQ :\n\r"; testoMail = testoMail + "IP : " + indirizzo + "\nPORTA : " + porta; mailInviata = mailHelper.sendMail(mail_to, oggettoMail, testoMail ); if (mailInviata==true){ // USCITA DAL CICLO esecuzioneProcedura = 0; // CHIUSURA DEL PROGRAMMA !!! System.exit(-1); } // MAIL AMMINISTRATORE AVVISO ERRORE // PULIZIA DELLA MEMORIA System.gc(); // INTERVALLO DI TEMPO (default 5 minuti) try { Thread.sleep(mail_wait_time); } catch (Exception e) {} // INCREMENTO IL TENTATIVO DI INVIO MAIL esecuzioneProcedura = esecuzioneProcedura + 1; } // FINE CICLO WHILE // CHIUSURA DEL PROGRAMMA !!! System.exit(-1); } }


Rispondi quotando