Thanks Avinash,
You are correct about the dynamic SQL, basically our product support a WEB UI that allow user to define the search criteria and then use it for querying database. With more than 10 million records, the query seem to run over and over although timed out has already occurred on WEB UI. That is the reason why I need a way to stop the query when timed out is hit.
As Dawn's suggestion has solved my problem by using setQueryTimeOut function of JDBC without killing the spid. And I think that is safe way.
Thanks for so much for your advice about sp_who/master...sysprocessess . I will pay attention on them in the future.
Thanks
Khoa Tran