我正在研究 GraphStream 显示数据库中的数据。但它创建节点和边缘的速度非常慢。我正在使用这个非常基本的示例。
这是我的代码:
public class GraphExplore {
static Connection conn2;
static String result, result2;
static JFrame frame;
static JPanel panel;
static int totalRows, i;
public static void main(String args[]) throws SQLException {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
showData();
} catch (SQLException e) {
e.printStackTrace();
}
}
});
}
private static void showData() throws SQLException {
frame = new JFrame("GRAPH TESTING");
Graph graph = new SingleGraph("tutorial 1");
graph.setAutoCreate(true);
graph.setStrict(false);
graph.display();
try {
Class.forName("org.h2.Driver");
conn2 = DriverManager.getConnection("jdbc:h2:file:G:/hs_data/h2_db/test", "sa", "sa");
} catch (Exception e) {
e.printStackTrace();
}
Statement stmt2 = conn2.createStatement();
ResultSet rs = stmt2.executeQuery("SELECT count(*) FROM cdr");
while (rs.next()) {
totalRows = rs.getInt(1);
}
ResultSet rs2 = stmt2.executeQuery("SELECT ANUMBER,BNUMBER FROM CDR LIMIT 20");
while (rs2.next()) {
result = rs2.getString("ANUMBER");
result2 = rs2.getString("BNUMBER");
graph.addNode(result);
graph.addNode(result2);
for (i = 0; i < totalRows; i++)
graph.addEdge("string" + i, result, result2);
}
for (Node node : graph) {
node.addAttribute("ui.label", node.getId());
}
// graph.addAttribute("ui.stylesheet", "graph { fill-color: red; }");text-mode:
// hidden;
graph.addAttribute("ui.stylesheet", "node {size: 12px;fill-color: #ff0000;z-index: 0;}");
graph.addAttribute("ui.stylesheet", "edge { shape:line ; fill-color: #222;}");
conn2.close();
}
}
现在,我只使用 20 行,需要 3-4 秒。但我需要一次显示更多记录(可能超过 100 万条)。谁能告诉我如何提高渲染速度?