Java单例模式示范
package com.ricoh.rapp.ezcx.iwbservice.util; import java.util.ArrayList; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.alibaba.fastjson.JSONObject; import com.ricoh.rapp.ezcx.iwbservice.model.IwbUsage; import com.ricoh.rapp.ezcx.iwbservice.webservice.HttpsRequest; public class UserLoginStatusUtil { private final Logger logger = LoggerFactory.getLogger(UserLoginStatusUtil.class); private static UserLoginStatusUtil userLoginInfo; private IwbUsage iwbUsage; private List<IwbUsage> iwbUsageList; public static UserLoginStatusUtil instance() { if (userLoginInfo == null) { synchronized (UserLoginStatusUtil.class) { if (userLoginInfo == null) { userLoginInfo = new UserLoginStatusUtil(); } } } return userLoginInfo; } public IwbUsage getIwbUsage() { return iwbUsage; } public void setIwbUsage(IwbUsage iwbUsage) { this.iwbUsage = iwbUsage; } public List<IwbUsage> getIwbUsageList() { if (iwbUsageList == null) { iwbUsageList = new ArrayList<IwbUsage>(); } return iwbUsageList; } public void setIwbUsageList(List<IwbUsage> iwbUsageList) { this.iwbUsageList = iwbUsageList; } public JSONObject sendHttpsReq(String ip, JSONObject requestJson) { // String url = "https://172.25.73.163:50005/api/v2/system"; String url = new StringBuilder("https://").append(ip).append(":").append(Constant.HttpsConstant.REQUEST_PORT) .append(Constant.HttpsConstant.REQUEST_SUF_URL).toString(); HttpsRequest request = new HttpsRequest(); logger.info("get login status url:" + url); JSONObject responseJson = request.httpsRequest(url, Constant.HttpsConstant.REQUEST_METHOD, requestJson.toString()); logger.info("login status https responseJson :" + responseJson); return responseJson; } }