Is executeUpdate method in Java thread safe

Do I have multiple threads trying to update a MySQL database? is the executeUpdate method used for streaming?

+1
source share
2 answers

No, it does not use streams.

In fact, if some other thread uses an instruction, and then another thread calls executeUpdate (), then the other ResultSet s thread, if any, will be closed. JavaDoc for java.sql.Statement (of which PreparedStatement is a subtype) "All execution methods in the Statement interface implicitly close the current ResultSet if one exists."

In addition, it is unlikely that this implementation of executeUpdate() will be written as safe for mulit-thread.

You must either synchronize all operator usage and result sets, or make multiple connections so that each thread uses its own JDBC Connection in the database. I would recommend the latter.

+3
source

Consider creating your update methods using a syncable keyword and think about your concurrency deadlocks there

0
source

All Articles