Threading problems are not a problem. Everything looks syntactically and functionally normal, and it should work for about half an hour. However, a topical issue is resource leakage. The application will crash in about half an hour, because you never close them after use. The database, in turn, will close the connection sooner or later so that it can return it back.
However, you do not need to worry about caching the finished data. The JDBC driver and database will take care of this task. Rather, worry about leaking resources and make your JDBC code as strong as possible.
public class ThreadedTask implements runnable { public run() { Connection connection = null; Statement statement = null; try { connection = DriverManager.getConnection(url); statement = connection.prepareStatement(sql);
To improve connection performance, use a connection pool, for example c3p0 (this, by the way, does not mean that you can change how you write JDBC code, always purchase and close resources in the shortest area in the try-finally block).
Balusc
source share