<div>Hi,</div>
<div> I use JSP and MySQL to develop .FDO connects these two parts together.</div>
<div> In the software,i use resource service and feature service to search data stored in the MySQL database.Once i run the page for searching.</div>
<div>I will got two sleep process in MySQL.I guess the reason is i forgot to close connections.So i go back to the code to close connections and services.No use.</div>
<div> </div>
<div>Codes here:</div>
<div>
<p>public Vector select(String mapName,String layerName,String layerClassName,String filterString) throws MgException<br>{<br> MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);<br>
MgFeatureService featService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);<br> <br> MgMap map = new MgMap();<br> map.Open(resService, mapName);</p>
<p> MgLayer layer = getLayerByName(map, layerName);</p>
<p> MgFeatureQueryOptions query = new MgFeatureQueryOptions();</p>
<p> query.SetFilter(filterString);<br> MgResourceIdentifier resId = new MgResourceIdentifier(layer.GetFeatureSourceId());<br> MgFeatureReader featureReader =featService.SelectFeatures(resId, layerClassName, query);<br>
Vector vec=new Vector();<br> while (featureReader.ReadNext())<br> {<br> <br> MgAgfReaderWriter geometryReaderWriter = new MgAgfReaderWriter();<br> String mc = featureReader.GetString("MC");<br> long id=featureReader.GetInt64("FeatId");<br>
long id1=featureReader.GetInt64("id");<br> MgByteReader byteReader = featureReader.GetGeometry("GEOMETRY");</p>
<p> MgGeometry geometry = geometryReaderWriter.Read(byteReader);<br> MgPoint point = geometry.GetCentroid();<br> double x = point.GetCoordinate().GetX();<br> double y = point.GetCoordinate().GetY();<br> xy n=new xy(x,y,id,id1,mc);<br>
vec.add(n);<br> geometryReaderWriter.delete(); //close<br> }</p>
<p> resService.delete(); //close<br> featService.delete(); //close<br> map.delete(); //close<br> return vec; </p>
<p>}</p>
<p>out of this function,i closed the connection to the site with "siteConnection.delete();"</p>
<p>Once i run this function ,checking the process of MySQL with "show processlist" in MySQL command shell,i will got two more sleep process,which can not be closed.</p>
<p>original:</p>
<p>mysql> show processlist;<br><br>| Id | User | Host | db | Command | Time | State | Info<br>| 1 | root | localhost:4955 | psd | Sleep | 2 | | NULL<br>| 193 | root | localhost:3941 | NULL | Query | 0 | NULL | show processlist |<br>
| 194 | root | localhost:3963 | jsof_data | Sleep | 4 | | NULL<br>| 195 | root | localhost:3964 | jsof_data | Sleep | 8 | | NULL<br><br>2 rows in set (0.00 sec)</p>
<p>ofter used the function:</p>
<p>mysql> show processlist;<br><br>| Id | User | Host | db | Command | Time | State | Info<br>| 1 | root | localhost:4955 | psd | Sleep | 2 | | NULL<br>| 193 | root | localhost:3941 | NULL | Query | 0 | NULL | show processlist |<br>
| 194 | root | localhost:3963 | jsof_data | Sleep | 4 | | NULL<br>| 195 | root | localhost:3964 | jsof_data | Sleep | 8 | | NULL<br>| 196 | root | localhost:3965 | jsof_data | Sleep | 2 | | NULL<br>
| 197 | root | localhost:3966 | jsof_data | Sleep | 3 | | NULL</p>
<p> </p>
<p><br>6 rows in set (0.00 sec)<br><br>i tried to kill the sleep process with the ways as follow:</p>
<p><%@ page language="java" import="java.util.*" pageEncoding="gb2312"%><br><%@ page import="java.sql.*"%><br><%@ page import="java.util.*"%><br><%@ page import="java.io.*"%></p>
<p><%<br> String path = request.getContextPath();<br> String basePath = request.getScheme() + "://"<br> + request.getServerName() + ":" + request.getServerPort()<br>
+ path + "/";<br> Class.forName("com.mysql.jdbc.Driver");<br> String url = "jdbc:mysql://localhost/psd?characterEncoding=utf8&user=root&password=root";<br>
Connection conn = DriverManager.getConnection(url);<br> Statement stmt = conn.createStatement();<br> Statement stmt2 = conn.createStatement();<br> ResultSet rs = stmt.executeQuery("show processlist");<br>
while (rs.next()) {<br> String Id = rs.getString("Id");<br> String cmd = rs.getString("Command");<br> String Time = rs.getString("Time");<br> int i = Integer.parseInt(Time); <br>
if(i>10&&cmd.equals("Sleep")) //Kill the process which has been slept for more than 10 seconds<br> stmt2.executeQuery("kill "+Id);<br> else<br>
}<br> rs.close();<br> stmt.close();<br> stmt2.close();<br> conn.close();<br>%></p>
<p>But i will get "The MySQL has gone away"error message.I have to restart MapGuideServer service to fix this problem.</p>
<p>Can anyhelp me on this problem?</p>
<p>Thanks for your attention:)</p>
<p>Jacky.</p></div>