1

I am using JAVA as my backend code and SQL server as my database server and i am calling a Stored procedure and it's very huge sp so i am breaking it into 3 sp's and calling it. but i just want to trigger one sp and it should continue it's task and only i should do is to check in every 1 min or so but i when i am calling the sp my java is waiting till the sp returns the value.

if i use webhook i can achieve this but i just want to use through stored procedure.

SimpleJdbcCall jdbcCall = new SimpleJdbcCall(Master.getJdbcTemplate).withProcedureName("sp_getDetails"); jdbcCall.setProcedureName("sp_getDetails");

Map m = jdbcCall.execute();

shridhar
  • 79
  • 1
  • 12
  • 1
    Have a look at java.util.concurrent.Future - essentially farm the call out to a background thread and choose when you want to look for the result. – Richard Jan 29 '19 at 11:41
  • @Richard Why don't you provide an example as an answer? – Dean Jan 29 '19 at 11:46
  • @Richard but i don't want any result i just want to fire a stored procedure and continue my other java work.i mean to say, the particular thread must suspend after calling that stored procedure. – shridhar Jan 29 '19 at 12:23

1 Answers1

2

One way of doing this is to make use of java.util.concurrent.FutureTask

ExecutorService executor = ...;
FutureTask<Map> future = new FutureTask<Map>(new Callable<Map>() {
    public Map call() {
        return jdbcCall.execute();
    }});
executor.execute(future);

You can then just ignore looking for the result of the future object - but the executor will run your call in a background thread and then just end. Meanwhile, the current thread (ie that makes the executor.execute call) will just carry on executing without blocking.

Richard
  • 9,740
  • 2
  • 23
  • 15