Killing IS running/hung services

Hi all,

Does anyone has java code to find the services which are running and to kill those services. we are having the problem where some services are going into deadlock situation…and finally we have to restart the server.

So, If anyone has java code…please share it. It would be very helpful.

regards,
david.

I found this link online and check if it is useful or not …
http://blog.hussulinux.com/2009/01/webmethods-kill-a-running-service-from-integration-server/

Hi raj,

Even I found that link…But when i tried to compile that code…I am getting this error.

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();

I am not that great in java. Do you have any idea about this error. Please help

Regards,
David.

we’re on 7.1.2. Can you try to compile the same code in your local machine. Its really important for me …because we’re into testing and due to some services the server is getting slow…and we have to go to Admin all the time to stop and restart the server.

What’s the reason behind hung services? Alternatively you can try reloading the package…

HTH!

You really really really should not be trying to kill running threads in a JVM. :eek: Killing running threads in a JVM can really have bad side effects. Find the cause of your hung services, because services in IS shouldn’t be hanging in the first place. If they are hanging its almost always a design or improper use issue.

Post what you have that is hanging up on you and maybe we can help you with some suggestions on how to make it work.

Hi,

Check if this thing helps.
//—BEGIN CODE—–
// Author:
// Date:
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 ():wink: {
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—–

Note:
I would not suggest to kill the thread,cause killing a thread is not a good practice & has adverse effects as rightly suggested by markg ;first try i out in test environment.

Regards.

Hi David,

You can replace “serverThread.getState()” with “serverThread.getInvokeState()” and try. You can see the comments section in the url mentioned by arul. It worked for me today.

Hi Mark,

Recently I had faced one scenario where I was required to kill a thread. I just want to let u know this and here ur comment.

Last month we had done load test in my QA (Test) server with some application where I need to trigger 10000 messages in an hour. After initiating the test, they found some processing issue in their application and asked me to stop the service in middle. First I tried with reloading the package having this service. It worked fine. But for second time when I faced the same issue, it didnt work, so we restarted the server as not having other option.

Regards,
skb

SKB,
You didn’t provide much here in the way of details about the architecture here so it’s hard for me to comment on it too much. In general reloading a package that is in the middle of processing transactions is a bad idea, it can lead to hung threads and corrupted transactions. That’s why package deployments are done during quiet hours.

Occasional hung threads like during a botched load test is not unreasonable and restart of the IS process is okay, better than trying to kill the thread. Although a better design would probably lead to a way to quiesce your service or even stop it correctly to accommodate.

Frequent hung threads within the IS is a sign of a design issue and should be corrected instead of trying to just treat it by killing it which will just ultimately make it worse.

I agree completely with Mark. Trying to kill threads, particularly if you’re “not that great in Java”, is a really, really bad idea.

Reloading package will not kill the thread.