main启动接口

package launch.com.sf.launch;

import java.lang.management.ManagementFactory;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.ws.Endpoint;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import serviceimp.com.sf.serviceimp.SayHiServiceImp;
import util.com.sf.util.Config;
import util.com.sf.util.ParseProperties;

/**
 * 发布WebService
 */
public class Main {
	private static Log logger=LogFactory.getLog(Main.class);
	private static String localIp = ManagementFactory.getRuntimeMXBean().getName();
	public static void main(String[] args) {
		if("1".equals(ParseProperties.getValue("hongkong"))){
			boolean bRet=Config.load();
			try {
				if(bRet){
					String service=ParseProperties.getValue("serviceIP");
					Endpoint.publish(service, new SayHiServiceImp());
					Config.printConfigs();
					heart();
					//http://10.118.63.43:8089/testjws/service/sayHi?wsdl
				}
			} catch (Exception e) {
				Config.printConfigsFail();
			}
		}
	}

	private static Long heartTime = 30 * 1000L;
	private static void heart() {
		while (true) {
			sleepTime(heartTime);
			if(localIp!=null){
				Config.getLog().writeLog(2, localIp+":"+heartBeatTask());
			}else{
				break;
			}
		}
	}
	
	private static  void sleepTime(Long heartTime) {
		try{
			Thread.sleep(heartTime);
		}catch(Exception e){
			logger.error("sleep error!" + e);
		}
	}
	public static String heartBeatTask() {
		SimpleDateFormat sdfBegin = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		return "心跳时间:"+sdfBegin.format(new Date());
	}
}

  

posted @ 2017-12-15 14:32  杯子茶壶  阅读(129)  评论(0)    收藏  举报