从java代码调用过程
我正在从java代码调用过程:从java代码调用过程,java,call,procedure,Java,Call,Procedure,我正在从java代码调用过程: private String processData(Integer time, String jndiName) { CallableStatement cs = null; Connection conn = null; try { InitialContext ctxt = new InitialContext(); DataSource ds = (DataSource) ctxt.lookup(jn
private String processData(Integer time, String jndiName) {
CallableStatement cs = null;
Connection conn = null;
try {
InitialContext ctxt = new InitialContext();
DataSource ds = (DataSource) ctxt.lookup(jndiName);
conn = ds.getConnection();
cs = conn.prepareCall("{call PROC(?)}");
cs.setInt(1, time);
cs.execute();
} catch (Exception e) {
}
这个程序只是等待我设置为参数的X秒
问题是:
当我使用参数time=30调用这个过程时,这个java函数需要多长时间?
它将等待此过程结束,或者java将运行它并继续执行下一个命令?是的,它将等待,这是一个阻塞操作。CS.execute是一个阻塞调用,等待数据库完成过程调用,然后只返回 hm是否有一些选项可以让我如何在另一个线程中运行它并在应用程序中继续?创建一个实现Runnable
的类,并将processData
方法包装在run
中。然后,您可以像这样调用它new Thread(new YourRunnable())。start()
@hudi可能很有意思,但有点不相关,但您应该在finally块中关闭连接(否则您将遇到连接泄漏)。