📄 mappoolservlet.java
字号:
package com.bro.map.pool;
/**
* <p>Title: MapService</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: BRO</p>
* @author 陈顺华
* @version 1.0
*/
import com.mapinfo.mapj.MapJ;
import javax.servlet.*;
import javax.servlet.http.*;
public class MapPoolServlet extends HttpServlet
{
MapJPool mapPool;
PoolThread poolThread;
/*地图数据文件路径*/
private String m_mapPath = "C:\\mapxtreme\\maps\\";
private String m_fileToLoad = "c:\\data\\world.mdf";
/*ServletContexName,供MapService调用*/
private String m_poolName = "MapPool";
/*池大小,线程睡眠时间*/
private int m_PoolSize = 20;
private long m_delay = 300000;
public void init(ServletConfig cfg) throws ServletException
{
super.init(cfg);
//ServletContextName
String strParam = getInitParameter("ServletContextName");
if(strParam != null)
m_poolName = strParam;
//地图文件,存放table 文件的路径
strParam = getInitParameter("mapPath");
if(strParam != null)
m_mapPath = strParam;
//地图集文件
strParam = getInitParameter("fileToLoad");
if(strParam != null)
m_fileToLoad = strParam;
//池大小
strParam = getInitParameter("PoolSize");
if(strParam != null)
m_PoolSize = Integer.valueOf(strParam).intValue();
//线程睡眠时间
strParam = getInitParameter("TreadDelay");
if(strParam != null)
m_delay = Long.valueOf(strParam).longValue();
mapPool = new MapJPool(m_PoolSize , m_fileToLoad);
poolThread = new PoolThread(mapPool , m_delay);
poolThread.start();
getServletContext().setAttribute(m_poolName , this);
System.out.println(m_poolName + "池创建成功");
}
public MapJ getMapJ() throws Exception
{
MapJ map = null;
if (mapPool != null)
{
map = mapPool.getMapJ();
}
return map;
}
public void destroy()
{
getServletContext().removeAttribute(m_poolName);
if (poolThread != null)
{
poolThread.stop();
poolThread = null;
}
if (mapPool != null)
{
mapPool.destroy();
}
super.destroy();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -