0

I am trying to kill the current process/query which is running from long and taking long time to execute

  • I want to do it with java servlets
  • I have a query and i ran it on my system but sometimes it is taking too much of time to get executed
  • What i am trying to do is to kill that query which is taking long time
  • I have google it a lot and found some help like with show processlist command in MySQL i can list up all the process which are currently in my system
  • like this it populates in my razor Sql click here to see process list
  • as you all can see in the image the process which is running has stae=Sending data so i want to kill that process with id where state=Sending data
  • as simply in my SQL command i can write kill id it will kill the process whose id i give
  • But i want to do this programmatically with java servlet code
  • I don't know how to do that,i am stuck here for so long

Below is my servlet do-Get and do-Post

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

}

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    doGet(request, response);
}

I just want to know how can i do it with with java code,please guide me anykind of help will be appreciated

This is the link i have found but not getting idea how to achieve that

  • 1
    You should consider improving your query performance, instead of killing the process. – Chinmay jain Mar 15 '19 at 09:35
  • no i can't ,i want to kill anyhow –  Mar 15 '19 at 09:36
  • You could set the max query timeout. If MySQL, starting from 5.7.8 there is a max_execution_time setting (https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_max_execution_time). – Chinmay jain Mar 15 '19 at 09:37
  • @Chinmayjain i am using MySQL 5.5, and i can't set max time out because, it is going to happen on the basis of user selection,when user clicks on UI(client-side) then i have to kill the query having state as Sending data –  Mar 15 '19 at 09:41
  • Possible duplicate of [How to stop a running mysql query](https://stackoverflow.com/questions/2065396/how-to-stop-a-running-mysql-query) – KevinO Mar 15 '19 at 09:55
  • @KevinO yup i already visited here,but there is no code like how can i write this in java servlet –  Mar 15 '19 at 09:57
  • I don't have a running mysql at the moment, but have you tried executing `show processlist;` in another connection? What does it return when there are running queries? One of the answers at that link certainly suggests that you will get the results. – KevinO Mar 15 '19 at 10:01
  • @KevinO yup sir i have tried `show processlist` it shows up me the full list of process as i have posted a image also,then with `kill id` i can kill it, but issue is i want to do this with java code how can i do that there –  Mar 15 '19 at 10:04
  • I don't think you followed the point. You can -- in java -- using a `statement` execute a query `show processlist` and (probably) get back the results, at least according to the suggestions from the link. – KevinO Mar 15 '19 at 10:06
  • @KevinO i am totally confused,i have visited that link but didn't understood how to do that,can you please help me with code? –  Mar 15 '19 at 10:07
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/190080/discussion-between-kevino-and-dheeraj-kumar). – KevinO Mar 15 '19 at 10:08

0 Answers0