/* This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * http://www.gnu.org/copyleft/gpl.html */ package net.sf.l2j.gameserver; import java.util.Calendar; import java.io.*; /** * This class writes the current server uptime * to a text file every second. * * @version $Revision: $ $Date: $ * @author AresXP */ public class GameServerUptime { public String _uptime_file = "uptime.txt"; private static GameServerUptime _instance; Calendar cal = Calendar.getInstance(); public long _uptime = (cal.getTimeInMillis() - GameServer.DateTimeServerStarted.getTimeInMillis()) / 1000L; class GrabUptime implements Runnable { public void run() { try { BufferedWriter fileout = new BufferedWriter(new FileWriter(_uptime_file)); fileout.write(Long.toString(_uptime)); fileout.flush(); fileout.close(); } catch(IOException e) { } ThreadPoolManager.getInstance().scheduleGeneral(new GrabUptime(), 1000); } } public static GameServerUptime getInstance() { if ( _instance == null ) _instance = new GameServerUptime(); return _instance; } private GameServerUptime() { ThreadPoolManager.getInstance().scheduleGeneral(new GrabUptime(), 1000); } }