V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
noble4cc
V2EX  ›  问与答

Java 在 mysql 中大量插入数据为什么一个进程中会存在多个线程?

  •  
  •   noble4cc · Apr 27, 2019 · 927 views
    This topic created in 2566 days ago, the information mentioned may be changed or developed.

    为了做测试我在本地 mysql 中插入了大量的数据大概几百万

    插入的要持续一段时间,但是我发现 java 的写入 mysql 的进程中有多个线程,但是我并没新开线程,只是简单的 for 循环

    是 mysql 驱动中插入的过程会多开线程吗?

    
    Connection connection = DB.getConnection();
                        PreparedStatement statement = null;
                        try {
                            connection = DB.getConnection();
                            for (int i = 0; i < 10000000; i++) {
                                String sql = "insert into post( title, uid, col1, col2, col3, col4) value(?,?,?,?,?,?)";
                                statement = connection.prepareStatement(sql);
                                String str = getRandomString(64);
                                statement.setString(1, getRandomString(16));
                                statement.setInt(2, random.nextInt(15792992));
                                statement.setString(3, str);
                                statement.setString(4, str);
                                statement.setString(5, str);
                                statement.setString(6, str);
                                statement.execute();
                            }
    
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
    
    watzds
        1
    watzds  
       Apr 28, 2019 via Android
    连接线程池,用完一个连接还得还回去
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3468 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 11:16 · PVG 19:16 · LAX 04:16 · JFK 07:16
    ♥ Do have faith in what you're doing.