Solved

Graceful shutdown of Axis web service?

Posted on 2004-08-03
8
495 Views
Last Modified: 2012-05-05
I have a web service deployed using Axis in JBOSS 3.2.1.  The service uses a class, SocketConnection, which has a static reference to a socket which always remains open.   I need to gracefully close this socket if the JBOSS server is brought down.  I tried adding a finalize method to the SocketConnection class but it isn't getting invoked.  Does anyone know how I can accomplish this?  Again, I have the classes deployed using Axis as defined in the wsdd file.
0
Comment
Question by:wmiddle
8 Comments
 
LVL 1

Expert Comment

by:wolfc
Comment Utility
Why close gracefully?

I have a SOAP service deployed using WSDP instead of Axis. If JBoss is shutting down something serious is going on, so it may go down in flames as far as I care.
0
 

Author Comment

by:wmiddle
Comment Utility
Actually the shutdown will be intentional
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
In a thread try to connect to the JBoss service. If it is not connected by thread then code your logic to shutdown ur service. Instead of checking wither JBoss service is existing or not at certain time intervals check for this. So it will not given burden to ur service aswell ur server.

Regards
Sudhakar
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> Actually the shutdown will be intentional

The close the socket when the shutdown is initiated.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:wmiddle
Comment Utility
>> In a thread try to connect to the JBoss service. If it is not connected by thread then code your logic to shutdown ur service

By the time the JBoss service is shut down I won't be able to shutdown my service.  The JVM will have exited by then

>> The close the socket when the shutdown is initiated
The shutdown is not initiated by the application.  it is someone hitting ctrl-C in the Jboss window

Aren't there any hooks into the shutdown sequence similar to a finalize method?  

Worst case scenario is I can provide a web method to shut down the socket connection and write a page or app that the operator would need to use before bringing down Jboss.  This wouldn't help with an unexpected or unplanned shutdown of Jboss.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
> it is someone hitting ctrl-C in the Jboss window

trap ctrl-c and do the shutdown

> Aren't there any hooks into the shutdown sequence similar to a finalize method?

Runtime.addShutdownHook()
0
 

Author Comment

by:wmiddle
Comment Utility
// In constructor of SocketConnection
SocketCloser closer = new SocketCloser(this);
Thread closerThread = new Thread(closer);
Runtime.getRuntime().addShutdownHook(closerThread);

// SocketCloser class
public class SocketCloser implements Runnable
{
      SocketConnection connection = null;

  public SocketCloser(SocketConnection connection)
  {
      super();
      this.connection = connection;
  }
  public void run()
  {
      connection.shutDown();      
  }
}
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
glad i could help :-)

http://www.objects.com.au/staff/mick
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now