⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginmanage.java

📁 WAP PUSH后台源码,WAP PUSH后台源码
💻 JAVA
字号:
package com.sxit.wap.staffuser;

import java.util.*;
import java.sql.*;
public class LoginManage {
 private Hashtable hash = new Hashtable();
 private int time = 3;   //分钟

 public int getTime(){
   return this.time;
 }

 public void setTime(int time){
   this.time = time;
 }

 public int size(){
   return hash.size();
 }
 public String getName(String userMdn){
    return ((UserManage)hash.get(userMdn)).getName();
 }

  public int getGroupId(String userMdn){
    return ((UserManage)hash.get(userMdn)).getGroupId();
  }

public void setHash(String userMdn,String userName,int groupId,Timestamp time){
  if(hash.size()>=100){
    this.clear();
  }
  UserManage message =new UserManage(userName,groupId,time);
  hash.put(userMdn,message);
}
public void loginReg(String userMdn,String userName,int groupId){
  Timestamp time = new Timestamp(System.currentTimeMillis());
  this.setHash(userMdn,userName,groupId,time);
}
public boolean isInOfTime(String userMdn){
   Timestamp tempTime1 = new Timestamp(System.currentTimeMillis());
   UserManage message =(UserManage) hash.get(userMdn);
   if (message != null) { //判断是否有记录
     long times = message.getTime().getTime() + this.time*60*1000;
     if (tempTime1.getTime() <= times) { //如果不超时,返回true;
       String name = message.getName();
       int groupId = message.getGroupId();
       this.setHash(userMdn,name,groupId,tempTime1); //更新记录数据
       return true;
     }else { //如果超时,返回false;
       return false;
     }
   }else { //如果没有纪录,返回false;
     return false;
   }
 }

public void clear(){
     Enumeration e = hash.keys();
     while (e.hasMoreElements()) {
       String user = (String) e.nextElement();
       UserManage message = (UserManage) hash.get(user);
       Timestamp tempTime1 = new Timestamp(System.currentTimeMillis());
       if (tempTime1.getTime() > message.getTime().getTime() + this.time * 60 * 1000) {
         hash.remove(user);
       }
     }
 }

public void clear(String userMdn){
   hash.remove(userMdn);
 }
 public static void main(String[] args){
   LoginManage login = new LoginManage();
   //login.setHash("1","1",new Timestamp(System.currentTimeMillis()));
   //login.setHash("1","1",new Timestamp(System.currentTimeMillis()));
   try{
     login.loginReg("1","1",333);
     System.out.println(new Timestamp(System.currentTimeMillis()));
     System.out.println("Sleeping.......");
     Thread.currentThread().sleep(1000*1*60 + 20*1000);
     if(login.isInOfTime("1")){
       System.out.println("没有超时");
     }else{
       System.out.println("超时");
     }
     System.out.println(new Timestamp(System.currentTimeMillis()));
   }catch(Exception ex){

   }
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -