Java statistics current online number

zhaozj2021-02-17  47

Package com.hnedu.stat; / ** * Calculate the number of online people, description: * * Add: * com.hnedu.stat.onlineCounter.adduser (Object Object) * Generally use IP as an Object's incoming value , Of course, if the site statistics land the number of online people, you can use the user name * as an Object incoming value. * * Call display online number * com.hnedu.stat.onlineCounter.getonlineCount () * * * com.hnedu.stat.onlineCounter.getonline () * Return to a list, store the incoming Object value in String [] Finally access the page time. * By crazyren 2003-08-05 email: c_crazyren@hotmail.com * / import java.util.List; import java.util.ArrayList; import javax.servlet.http.HttpSession; public class OnlineCounter {private static List list = new ArrayList ();

Private onlineCounter ()} public static void adduser (Object Object) {// Get user current access time string nowtime = com.hnedu.util.StringUtils.gettime ("mm: s"); // STR array is used to store users IP and access time string [] str = new string [2]; str [0] = Object.toString (); str [1] = nowtime;

// Temp array is used to hold the user IP and access time taken from the list [] temp = new string [2];

// Cycle List for (INT i = 0; i 300) {list.remove (i);}} // Add a new online user list (STR); // Release resource str = null; Temp = NULL }

Public static int getonlineCount () {// Returns the current online number Return list.size ();

Public static list getonline () {return list;} / ** calculate two time difference, return to phase differences * / private static int subtime (string src, string des) {int n = 0; java.util.calendar ca = Java .util.calendar.GetInstance (); long time1 = com.hnedu.util.stringutils.comPareStringTime (SRC, DES, "MM: SS"); ca.settimeinmillis (Time1); n = (java.util) .Calendar.minute)) * 60; n = n ca.get (java.util.calendar.second); Return n;}} The two methods inside the StringUTILS:

/ ** * Get the current time * @Param Parrten output time format * @return returns time * / public static string gettime (string parrten) {string timeStr; if (Parrten == null || Parrten.equals (")) {PARRTEN = "YYYYMMDDHMMMMS";} java.text.SIMPLEDATEFORMAT SDF = New SimpleDateFormat (PARRTEN); java.util.date CDAY = New Date (); TIMESTR = SDF.FORMAT (CDAY); Return TimeStr;}

/ ** * Compare two string time size * @PARAM T1 time 1 * @Param T2 time 2 * @Param Parrten time format: YYYY-mm-dd * @return Return long = 0 equal,> 0 T1> T2 , <0 t1

转载请注明原文地址:https://www.9cbs.com/read-29121.html

New Post(0)