Webmethods:How to Kill a Running Service from the Integration Server

Many of you have wondered how to kill a WebMethods service while its running on the Integration Server.

Its become a Pet Interview Question for many but the interviewer also expects one of the following facts which is not the most recommended method to kill a running service.

Here are some facts:

1. If you are running the service on debug mode, the service will get killed if you kill your developer.
2. If you are running the service on RUN mode, the service runs on the Integration Server and will not get killed.
3. If your client has activated the service but terminated the session, the service will still run on the IS.
4. If your webmethod service is hung, You will try to Reload the entire package. But this will NOT help.
5. You will also try to unload the package but this will NOT help too.

What you need to do is on a Thread Level. The idea is quite simple: Just get the list of all the current running threads and kill the service which you need.

I will try to explain this in a step by step manner. Developers please do try it out on your dev boxes as well.

Step 1:
Create a Flow service like this:

wm1

Step 2:
Lets create a Flow service which will get ALL running threads. This should take NO input but lets output a String containing all running threads on that Integration Server.

w2

Step 3:

Insert the following Java Code in your WebMethods Flow Service that you just created. The code is commented well enough.

//—BEGIN CODE—–
// Author: Hussain Fakhruddin (hussulinux@gmail.com)
// Date: 20090128
//Get the Current Thread
Thread currentThread = Thread.currentThread();
//Get all Thread Groups.
ThreadGroup rootThreadGroup = currentThread.getThreadGroup();
//Traverse to the Top Thread Level
while (rootThreadGroup.getParent() != null) {
rootThreadGroup  = rootThreadGroup.getParent();
}
//Getting all Threads
Thread [] threads = new Thread[1000];
int threadCount = rootThreadGroup.enumerate(threads, true);
String threadList = “”;
// Now traverse through all the Threads and use the ServerThread API from webmethods to get all the thread detail.
int i=0;
for (; i<threadCount ; ++i){
if (threads[i] instanceof com.wm.app.b2b.server.ServerThread) {
//Casting a raw thread into ServerThread type
com.wm.app.b2b.server.ServerThread serverThread = (com.wm.app.b2b.server.ServerThread) threads[i];
//Getting the service Name for which the thread belongs to
if (serverThread.getState().getService() != null){
threadList = threadList + serverThread.getState().toString() ;
java.util.Stack threadStack = (java.util.Stack) serverThread.getState().getCallStack();
for (Iterator iter=threadStack.iterator(); iter.hasNext();) {
Object threadObj = iter.next();
threadList = threadList + “\n ” + threadObj.getClass().getName();
threadList = threadList + “, ” + threadObj.toString();
}
}
}
}
IDataCursor cursor = pipeline.getCursor();
cursor.insertAfter(“threads”, threadList);
cursor.destroy();

//—–END OF CODE—–

Step 4: Now lets create another flow service “killThread” with the following inputs and outputs

wm3

Step 5: Now copy paste the following code. We’re going to traverse through the entire list and call the .interrupt() method to kill the process. Note: you need to provide FULL path of the service which you want to kill. You can get the full path from the webmethods admin panel (under package management).

//—BEGIN CODE—–
// Author: Hussain Fakhruddin(hussulinux@gmail.com)
// Date: 20090128
IDataCursor cursor = pipeline.getCursor ();
if (cursor.first (“serviceName”)) {
String serviceName = (String) cursor.getValue ();
Thread current = Thread.currentThread ();
ThreadGroup root = current.getThreadGroup ();
while (root.getParent () != null) {
root = root.getParent ();
}
Thread [] threads = new Thread [1000];
int count = root.enumerate (threads, true);
String sb = “Not Found”;
StringBuffer killedList = new StringBuffer ();
for (int i=0; i<count; i++) {
if (threads[i] instanceof com.wm.app.b2b.server.ServerThread) {
com.wm.app.b2b.server.ServerThread serverThread = (com.wm.app.b2b.server.ServerThread) threads[i];
if (serverThread.getState ().getService () != null) {
java.util.Stack stack = (java.util.Stack) serverThread.getState ().getCallStack ();
for (Iterator iter=stack.iterator (); iter.hasNext ();) {
Object obj = iter.next ();
String name = obj.toString ();
if (name.trim().equals (serviceName)) {
threads[i].interrupt ();
sb = “Interrupted”;
killedList.append (stack.toString ()).append (“\n”);
}
}
}
}
}
cursor.insertAfter (“status”, sb);
cursor.insertAfter (“killedList”, killedList.toString ());
cursor.destroy ();
}
//—–END OF CODE—–

That’s it folks! Save and run it.. Come back to me if you face problems..

Join the Conversation

80 Comments

  1. Hi Hussain,

    Thanks for this wonderful post on webmethods. Our company has been trying this out since long time and you’ve created just the right way….

    I will be implementing this in our UAT environment right away and send out for testing.

    Could you please pass me your email id, I’d like to discuss more things with you privately.

    Regards,

    Stanley
    Head of Technological Services,
    Cansoft India Pvt.Ltd.

  2. Hussain,

    Excellent work as well. Although, I am not in webmethods integration now days, but i remembered that stopping a service that is long running was not possible.

    Excellent work and all the very best and keep blogging. You ignited me to start blogging as well [;)]

    Sirat Moin,
    Sr. Integration Consultant

  3. Really a neat way to kill. I was just amazed we could use simple Java and stop the services… Ive tried this and it worked although I had doubts…!! Thanks a lot…! Can I have your email address, I would like to discuss a few more things with you.

    Yudi Ivankof.
    Project Manager,Romanian Technological Services.

  4. I tried to run the service found following errors . Please help.

    /opt/webmethods71/IntegrationServer/packages/N045605/code/source/N045605/utils.java:65: cannot find symbol
    symbol : method getService()
    location: class java.lang.Thread.State
    if (serverThread.getState().getService() != null){
    ^
    /opt/webmethods71/IntegrationServer/packages/N045605/code/source/N045605/utils.java:67: cannot find symbol
    symbol : method getCallStack()
    location: class java.lang.Thread.State
    java.util.Stack threadStack = (java.util.Stack) serverThread.getState().getCallStack();

  5. Hi Hussain,

    Thanks for the great tool. I’m sure this will be helpfull, but I am also having the same error.

    What server librairies are you talking about exactly?

    Thanks in advance for your help.

    ————-

    /wmbadv1/IntegrationServer/packages/ft_temp/code/source/ft_temp.java:64: cannot find symbol
    symbol : method getService()
    location: class java.lang.Thread.State
    if (serverThread.getState().getService() != null){
    ^
    /wmbadv1/IntegrationServer/packages/ft_temp/code/source/ft_temp.java:66: cannot find symbol
    symbol : method getCallStack()
    location: class java.lang.Thread.State
    java.util.Stack threadStack = (java.util.Stack) serverThread.getState().getCallStack();
    ^
    2 errors

  6. Francis,

    Looks like getState() is deprecated now. Try the following,it works..

    ————————

    IDataCursor cursor = pipeline.getCursor ();
    if (cursor.first (“serviceName”)) {
    String serviceName = (String) cursor.getValue ();
    Thread current = Thread.currentThread ();
    ThreadGroup root = current.getThreadGroup ();
    while (root.getParent () != null) {
    root = root.getParent ();
    }
    Thread [] threads = new Thread [1000];
    int count = root.enumerate (threads, true);
    String sb = “Not Found”;
    StringBuffer killedList = new StringBuffer ();
    for (int i=0; i<count; i++) {
    if (threads[i] instanceof com.wm.app.b2b.server.ServerThread) {
    com.wm.app.b2b.server.ServerThread serverThread = (com.wm.app.b2b.server.ServerThread) threads[i];
    if (serverThread.getInvokeState ().getService () != null) {
    java.util.Stack stack = (java.util.Stack) serverThread.getInvokeState ().getCallStack ();
    for (Iterator iter=stack.iterator (); iter.hasNext ();) {
    Object obj = iter.next ();
    String name = obj.toString ();
    if (name.trim().equals (serviceName)) {
    threads[i].interrupt ();
    sb = “Interrupted”;
    killedList.append (stack.toString ()).append (“\n”);
    }
    }
    }
    }
    }
    cursor.insertAfter (“status”, sb);
    cursor.insertAfter (“killedList”, killedList.toString ());
    cursor.destroy ();
    }

  7. /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:45: illegal character: \8221
    if (cursor.first (\u201DserviceName\u201D)) {
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:45: illegal character: \8221
    if (cursor.first (\u201DserviceName\u201D)) {
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:54: illegal character: \8220
    String sb = \u201CNot Found\u201D;
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:54: illegal character: \8221
    String sb = \u201CNot Found\u201D;
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:66: illegal character: \8220
    sb = \u201CInterrupted\u201D;
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:66: illegal character: \8221
    sb = \u201CInterrupted\u201D;
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:67: illegal character: \8221
    killedList.append (stack.toString ()).append (\u201D\n\u201D);
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:67: illegal character: \92
    killedList.append (stack.toString ()).append (\u201D\n\u201D);
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:67: illegal character: \8221
    killedList.append (stack.toString ()).append (\u201D\n\u201D);
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:73: illegal character: \8221
    cursor.insertAfter (\u201Dstatus\u201D, sb);
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:73: illegal character: \8221
    cursor.insertAfter (\u201Dstatus\u201D, sb);
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:74: illegal character: \8221
    cursor.insertAfter (\u201DkilledList\u201D, killedList.toString ());
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:74: illegal character: \8221
    cursor.insertAfter (\u201DkilledList\u201D, killedList.toString ());
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:77: ‘)’ expected
    // — <> —
    ^
    /opt/webmethods-dev1/IntegrationServer/packages/N676074/code/source/N676074/utils.java:80: illegal start of expression
    }
    ^
    15 errors

  8. replace ” with manual type as they are transferred as specially encoded character while copy and paste

  9. Prashant,

    It seems you are copying the code from browser and past that to wM developer.

    Try, using different editor (TextPad) change the quotes to “smart quotes” and then past that on to webMethods Developer.

  10. Prashant,

    It seems you are copying the code from browser and paste that to wM developer.

    Try, using different editor (TextPad) change the quotes to “smart quotes” and then paste that on to webMethods Developer and then compile.

  11. Prashant,

    It seems you are copying the code from browser and paste that to wM developer.

    Try, using different editor (TextPad) change the quotes to “smart quotes” and then paste that on to webMethods Developer and then compile.

  12. Excellent post Hussain.
    I was wondering if Unix or AIX platform allows you to kill the threads by some of their utilities instead of writing java services, do you something about that?

    Thanks,
    Ishti.

  13. Hi,

    Actually in Unix /Aix we have processes but as far as Java is concerned, the thread runs under Java environment and we’re trying to kill those threads and not processes.
    We shouldn’t confuse between forked child processes and threads in Java.

    I am not sure if JVM provides any mechanism by which a thread can be killed by some OS call.

    Regards,
    Hussain

  14. Good day. To start with I would like to say that I truly like your webpage, just determined it the past week but I’ve been following it sometimes since then.

    I appear to concur with most of your thinkings and opinions and this post is no exception. I fully

    Thank you to get a fantastic web site and I hope you preserve up the beneficial operate. If you do I will keep on to checked out it.

    Have a great evening.

  15. Hi Hussain!

    I see that killing a thread is deprecated in JAVA. Can you pls suggest me whether your utility is safe to interrupt a HUNG service.

  16. I have a scenario where, there were 4 hung threads for the given service and 2 HUNG threads for its child service. When I ran the killThread service, output was perfect. It gave the total list of all the 6 services and status was “Interrupted”. When I checked it in webM IS Console->service usage, I still see the number of HUNG threads as it is.
    Again I ran the service, the output was same(Displayes all the 6 services with status “Interrupted”). If I run 10 times, Im getting the same output, but its not actually Interrupting. Pls advise me on this.

  17. Hi Hussain,

    This java code works really well thanks for posting.
    As I have an environment where more than 50 inegration servers are running, in which hung services may come on any server any time.
    if I have to implement above kill thread service in my environment I have to deploy this service in each and every integration service which is quiet heavy. Is there any way we can have this service in common place from where we can kill any IS hung service in the envirronment. ideas are welcome from all.

  18. Usually you need to kill a thread becasue its hung , so you rather not care about doing it gracefully. So this method works perfectly well. If you need thread to die with proper non-depricated API then you’ll have to program it that way.. !

  19. Hello,

    I have tried the following :

    1- Created a simple service which repeats on Success and get the current date
    2- I run the service from developer (it runs forever)
    3- I go to my browser and issue the following URL :
    http://IShostname:5454/invoke/JeremyTest.serviceThreads:killThread?serviceName=JeremyTest:loopService
    4- I get the following reply :
    serviceName JeremyTest:loopService
    status Interrupted
    killedList [JeremyTest:loopService, PSUtilities.misc:sleep]
    serviceNameList JeremyTest:loopService

    But when I check Developer, the service is still running with progress bar and when I check running services, the service JeremyTest:loopService is still running as well…

    Please could you advise? It it problem to kill a loop?

    Thanks a lot !


    Jeremy

  20. I am facing the same problem with 2 errors.
    What server libariaries to be included.
    Please guide me.

    error:

    /opt/WebMethods/is500/IntegrationServer/packages/CommService/code/source/CommService/thread.java:63: cannot find symbol
    symbol : method getService()
    location: class java.lang.Thread.State
    if (serverThread.getState().getService()!= null)
    ^
    /opt/WebMethods/is500/IntegrationServer/packages/CommService/code/source/CommService/thread.java:66: cannot find symbol
    symbol : method getCallStack()
    location: class java.lang.Thread.State
    java.util.Stack threadStack = (java.util.Stack) serverThread.getState().getCallStack();
    ^
    2 errors

  21. Hi Hussain,

    Greetings to you. I am relatively new to webMethods Java services. I chanced upon your blog and was really very impressed. Please keep blogging it inspires others a great deal.

    Kudos!!!

    Regards
    Intekhab

  22. Hi,
    i have the same issue that is said like 10 post back the one that put Jeremy!
    1- Created a simple service which repeats on Success and get the current date
    2- I run the service from developer (it runs forever)
    3- I get the following reply :
    serviceName JeremyTest:loopService
    status Interrupted
    killedList [EApaza.mapping:test , pub.string:concat]

    it seems to be that, is not working if your thread inside has an loop element. can anyone answer me this issue? thank you all!!

  23. Hi

    Can anyone help me with below errors,

    /opt/webMethodsBT2Test/IntegrationServer/packages/Default/code/source/karan.java:53: illegal character: \8220
    String threadList = \u201C\u201D;
    ^
    /opt/webMethodsBT2Test/IntegrationServer/packages/Default/code/source/karan.java:53: illegal character: \8221
    String threadList = \u201C\u201D;
    ^
    /opt/webMethodsBT2Test/IntegrationServer/packages/Default/code/source/karan.java:66: illegal character: \8220
    threadList = threadList + \u201C\n \u201D + threadObj.getClass().getName();
    ^
    /opt/webMethodsBT2Test/IntegrationServer/packages/Default/code/source/karan.java:66: illegal character: \92
    threadList = threadList + \u201C\n \u201D + threadObj.getClass().getName();
    ^
    /opt/webMethodsBT2Test/IntegrationServer/packages/Default/code/source/karan.java:66: illegal character: \8221
    threadList = threadList + \u201C\n \u201D + threadObj.getClass().getName();
    ^
    /opt/webMethodsBT2Test/IntegrationServer/packages/Default/code/source/karan.java:67: illegal character: \8220
    threadList = threadList + \u201C, \u201D + threadObj.toString();
    ^
    /opt/webMethodsBT2Test/IntegrationServer/packages/Default/code/source/karan.java:67: illegal character: \8221
    threadList = threadList + \u201C, \u201D + threadObj.toString();
    ^
    /opt/webMethodsBT2Test/IntegrationServer/packages/Default/code/source/karan.java:73: illegal character: \8220
    cursor.insertAfter(\u201Cthreads\u201D, threadList);
    ^
    /opt/webMethodsBT2Test/IntegrationServer/packages/Default/code/source/karan.java:73: illegal character: \8221
    cursor.insertAfter(\u201Cthreads\u201D, threadList);
    ^
    /opt/webMethodsBT2Test/IntegrationServer/packages/Default/code/source/karan.java:73: ‘)’ expected
    cursor.insertAfter(\u201Cthreads\u201D, threadList);
    ^
    10 errors

  24. I absolutely love your blog and find many of your post’s to be what precisely I’m looking for.
    Does one offer guest writers to write content for you?
    I wouldn’t mind publishing a post or elaborating on a few of the subjects you write with regards to here. Again, awesome web site!

  25. Only five days ahead of my very own very first recorded set open up-atmosphere celebration about new music, all the Jamboree Evening time, and it also was essentially flowing birds. There is whenever a period which running shoes tend to be sports footwear, having a homogeneous various textures concerning fabric product, the particular choice essential should be to obtain reduced running shoes or even elevated seeker wellingtons.

  26. I guess getService() and getCallStack() methods of serverThread are not able …

    Me too Getting the error on …
    1–>if (serverThread.getState().getService() != null)
    2—>java.util.Stack threadStack = (java.util.Stack) serverThread.getState().getCallStack();

  27. Hi Hussain,

    Code seems to be fine ..its displaying hang threads…but its not able to kill the threads even though in output it showing that Status is Interrupted but i observed that that service is still running in IS Admin page.
    Pls let me know if u have any idea .

    Thanks,
    Raj.

  28. Excellent Post. I tried implemeting code provided by you however got error Looks like getState() is deprecated now.I have implemented the code provided by Sundar Patnaik.Service is running fine its giving me output for status as Interrupted and services name in killedList.However from Admin page when I checked I can service is still running,Please help

  29. The unmatched Brat Chanel is essentially established in three fashions, The littlest being employed as a transport therefore the biggest as the travel bag. Established in charge with Chanel, A someone’s colors tint option map possesses a level burgandy, Expressive dunkelhrrutige, Active with a towel hoar tint, Maneuver eco-kindly disposed|friendly}, As cleansed reduced seeing|light} colored in really complicated calfskin. Take away from range is likely to be $2500 $4300 effectively as the bags will for sure come at July,

  30. I see a lot of interesting articles on your blog.
    You have to spend a lot of time writing, i know how
    to save you a lot of time, there is a tool
    that creates readable, SEO friendly articles in couple of seconds, just search in google – k2 unlimited content

  31. Hi Hussain,

    Very useful post for wM users. Thanks a lot. Appreciate your step by step vivid description.
    Though killThreads service displays status as interrupted, admin page shows this service as running.
    Kindly advise me how to stop executing service.

  32. Thanks a lot for this useful code.

    Is that possible to fetch the timestamp along with running services using java?

  33. Hi,

    We are using Trading network to receive the documents from a vendor. But from a few days we are not receiving the documents. We are using the HTTPS for achieving this. We have restarted the server many times with no luck.
    Vendor is receiving 403 error.
    Is when the IS restarted the previously suspended jobs run again themselves and may preventing new documents to come.
    Any help will be appreciated.

  34. I just wanted to thank you again for the amazing web page you have designed here. It truly is full of useful tips for those who are definitely interested in that subject, in particular this very post. Youre really all so sweet plus thoughtful of others and also reading your website posts is an excellent delight to me. And what generous reward! Ben and I will have excitement making use of your recommendations in what we should instead do in a few weeks. Our collection of ideas is a distance long which means that your tips will be put to very good use.

  35. 精准医疗又叫个性化医疗,是指以个人基因组信息为基础,结合蛋白质组,代谢组等相关内环境信息,为病人量身设计出最佳治疗方案,以期达到治疗效果最大化和副作用最小化的一门定制医疗模式。因此相较传统医疗,精准医疗具有针对性、高效性及预防性等特征。

    美国医学界在2011年首次提出了“精准医学”的概念,今年1月20日,奥巴马又在美国国情咨文中提出“精准医学计划”,希望精准医学可以引领一个医学新时代。10月8日,2015全球创新论坛纽约峰会在纽约穆迪总部大楼举办。乐土投资集团CEO刘如银在峰会上介绍了他的精准医疗生态圈的想法。

    刘如银介绍了乐土投资在美国的国际化实践,包括在美国的地产投资拓展,以及最新投资的医疗健康项目。乐土投资集团(CLIG)定位以硅谷的高科技投资为引擎,以科技医疗和互联网金融为两翼,链接最具价值的深科技健康项目,服务国际大健康和科技发展。

    美国财政预算计划在2016年拨付给美国国立卫生研究院(NIH)、美国食品药品监督管理局(FDA)、美国国家医疗信息技术协调办公室(ONC)等机构共2.15亿美元用于资助这方面的科学研究与创新发展。

    刘如银说:美国的精准医疗主要是围绕着基因组、蛋白组等方面的检测,也就是围绕分子生物学的特性,针对个体化的病理特征进行治疗。而我们所关注的不仅如此,更是系统化的,全过程、全要素、全局性的对医疗过程和临床实践进行优化。我们所指的精准医疗也是针对每一个病人的具体病情,正确选择并精确的应用适当的治疗方法。刘如银认为:精准医疗的最终目标是以最小化的医源性损害、最低化的医疗资源耗费去获得最大化的病患的效益,其前景不可限量。

    精准医疗要做到个性、高效及预防的关键在于筛查和诊断,因此基因测序等检测诊断技术的发展是关键。成本的下降让基因测序商业化市场的打开成为可能,基因测序技术的成熟和商用经过了多年的发展,1980 年自动测序仪出现,2001 年完成了人类基因组框架图标志着这一技术的成熟,2007 年二代基因测序技术大幅降低测序成本,使得这一技术应用出现可能,以走在前列的Illumina 公司为例,该公司自2007 年起把当时每个基因组的测序成本费用从1000万美元降到了当下的1000 美元, 根据Illumina 公司数据,全球NGS(二代基因测序)的应用市场规模预计为200 亿美元,药品研发和临床应用是增速最快的领域,增速超过15%,肿瘤诊断和个性化用药是最有应用前景的领域,市场规模120亿美元。乐土投资与Illumina以及新一代的基因检测公司Genalyte, Centrillion都有着合作关系。

    刘如银说:精准医疗作为医疗模式的革新对提高我国国民健康水平有重要意义,将在基因测序技术发展和国家政策的推动下迎来黄金发展期。精准治疗是下一个新兴朝阳行业,我们关注基因测序、肿瘤诊断及个性化用药等相关投资机会。

    全球创新论坛纽约峰会由全美华人金融协会(The Chinese Finance Association, TCFA) 主办。全美华人金融协会于一九九四年在美国成立。分布在世界各地的会员来自华尔街投行、基金、监管部门、和学术界,已成为联系中美金融界最重要的桥梁之一。协会定期举行学术年会。协会本部设在纽约,并在波士顿,华盛顿,旧金山,伦敦,香港,北京和上海等金融中心设有分会。

    原招商银行行长马蔚华,中信银行美国分行行长文兵,汉世纪投资管理有限公司合伙人吴皓,联合国南南合作办首席经济与投资专家杨庆宏等参加了本年度会议并发表了讲话。

  36. 、私はあなたの注目度抜群の掲示の記事の3を見て、あなたは往復のページに興味がある場合に尋ねるために必要な?乗組員は、アレクシス·テキサスのお尻についてのブログを持っています!とにかく、私の言語で、通常はこのような多くの十分な供給がありません。

Leave a comment

Your email address will not be published. Required fields are marked *