English 中文(简体)
• 加快多家JDBCQQ矿?
原标题:Speed up multiple JDBC SQL querys?

I m在一条最短的道路上工作,在java使用一种 algorithm泥 d法。 I m 在该方案中执行以下Kkouery approx 300倍,以便从10 000辆公共汽车连接数据库中找到通道。 大约需要6-7秒才能执行300次询问。 关于我如何加快这项工作的建议,或关于一种可使用的不同方法的任何想法? 增 编

private HashMap<Coordinate,Node> closedNodes;
private PriorityQueue<Node> openNodes;

..
private List<Coordinate> calculatePath() 
{
    //While there are nodes in the open list
    while (!openNodes.isEmpty()) 
    {
        //Get the node with the lowest gVal+hVal
        Node node = openNodes.poll();
        //Add it to the closed list
        closedNodes.put(node);
        //If it is not the goal node
        if (!node.equals(goal)) 
        {   
            //Get all the neighbours and Create neighbour node
            List<Node> neighbours = helper.getNeighbours(node, goal);
            //For each neighbour
            for (Node neighbourNode : neighbours) 
            {
                //Check if the neighbour is in the list of open nodes
                boolean isInOpen = checkOpenNodes(neighbourNode);
                //If it is not in the open nodes and not in the closed nodes
                if ((!closedNodes.containsKey(neighbourNode))&& (!isInOpen)) 
                {
                    //Add it to the list of open nodes
                    openNodes.add(neighbourNode);
                }
            }
        }
        else 
        {
            // We found the path
            path = backTrackPath(node);
            break;              
        }
    }
    return path;

/**
 * Gets the list of valid Nodes that are possible to travel to from <b>Node</b>
 * @param stopNode Node to find neighbours for
 * @param goal End Node
 * @return list of neighbour Nodes
 */
public ArrayList<Node> getNeighbours(Node stopNode, Node goal) 
{
    ArrayList<Node> neighbours = new ArrayList<Node>(); 
    Node neighbourNode;     
    //get neighbours connected to stop  
        try {
            ResultSet rs = stmt.executeQuery("select To_Station_id, To_Station_routeID, To_Station_stopID," +
                    "To_Station_lat, To_Station_lng, Time from connections  where Connections.From_Station_stopID ="
                    +stopNode.getCoord().getStopID()+" ORDER BY Connections.Time");

            rs = stmt.getResultSet();
            while (rs.next()) {
                int id = rs.getInt("To_Station_id");
                String routeID = rs.getString("To_Station_routeID");
                String stopID = rs.getString("To_Station_stopID");
                String stopName = rs.getString("To_Station_stopName");
                Double lat = rs.getDouble("To_Station_lat");
                Double lng = rs.getDouble("To_Station_lng");
                int time = rs.getInt("Time");
                neighbourNode = new Node(id, routeID, stopID, stopName, lat, lng);
                neighbourNode.prev = stopNode;
                neighbourNode.gVal = stopNode.gVal + time;
                neighbourNode.hVal = heuristic.calculateHeuristic(neighbourNode, goal);
                neighbours.add(neighbourNode);
            }
        }
    catch (SQLException e) {
        e.printStackTrace();
    }
    return neighbours;
}
最佳回答

总的来说,如果你的询问速度缓慢而且费用昂贵,就试图在某个地方取得结果,那么下一次调查将迅速从海滩上收回。 因此,你(临时)将(暂时)计算A点和B点之间的连接,储存数据库其他(临时)桌上设定的全部结果,确定寿命,因此,在下一个X小时/日(或直到路线改变)上,你可以从该桌上从A到B处收回路线。

问题回答
  1. Make sure you have an index on connections.From_Station_stopID
  2. Instead of SELECT *, only select the columns you need
  3. If only the constant in the WHERE clause for From_Station_stopID changes each time, use a parameterized, prepared query so that the database doesn t have to parse the query and build the execution path each time, or combine the queries into one using WHERE From_Station_stopID IN (value1, value2, ...)
  4. If you re repeating the same queries often, ensure that MySQL is using query caching

如果你向我们展示了守则的其余部分,那它会 lo起300次我们可能能够进一步帮助的提问。

总的来说,我可以说,如果你每次重新计算最短的道路,那么你就应当建立一个像电网一样的表格,每个路段的路途距离预先计算,或者甚至从每个路段预先计算出的整个路线。

我的理解是,你有一张标子和连接点的图表。

想制造一些标语,作为图象(在最简单的情况下可以是矩阵),并对标语进行检索。 然后,你不需要向您的数据库发出300条电话,而从业绩的角度来看,这些电话非常昂贵。

首先,你们应当使用一个发言稿,而不是一个正常的问询,而且每次都使用<代码>stmt.setInt(1, 制止Id)。

此外,最好选择你感兴趣的具体领域,而不是<代码>。

这些只是亚行的一般规则,可能不会对时间产生巨大影响,但值得这样做。

之后,我将试图调查表格索引,以确保根据从_站到站的查询。 国际发展法确实像现在这样快速执行。

如果是,而且唯一的间接费用是单独向数据库发出的电话,那么下一步可能是试图将询问合并起来,或许是将其编成“条码”从连接点(......、......、......)

根据表格的大小,你可能只想把全部东西事先装上记忆(或许是哈希姆普),然后,你就不必去数据库。

简言之,这在很大程度上取决于问题的不同参数,你们需要检查一下,什么解决办法对你来说是最好的。

您只能使用IN条款,以便一劳永逸地处理问题——从连接点选择*。 From_Station_stopID 页: 1





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签