Good way to manage running Java service

I have a small Java http server, and I'm looking for a way to be able to tell it to shut down. As of now, it listens for a special "/SHUTDOWN" HTTP request, but I don't like that as any Joe Schmoe can do it. I can limit that to only coming from the localhost (a server), but still has the "anybody" issue.
I'd like to get it to something I can invoke from the command line. In C++ I'd just send a signal, but that's not supported in Java and I'm not too hot to dig into JNI just for this.
Any ideas for a good way to go about this?

Make a shutdown hook and crtl-c the java program. That will invoke the shutdown hook and make it have a clean stop.
Still applies for the any user thing though. :(
There are some tools out there for wrapping java programs as services (for windows).
As far your invoking from command line.
Well you could always make the server have a flag called -stop for example that instead of launching the actual web server sends a shutdown request by HTTP or whatever to the server on the localhost.

Similar Messages

  • What's a good way to manage custom schema for DS  5.1?

    What's a good way to manage custom schema?
    Custom Schema for Object Class and Attributes
    The reason I ask this is because there might be a need in the future where I need to export those custome schema into different branded directory server. I just want to make this as painless as possible.
    Right now, I thought of 2 options
    1) Create my own LDIF file with my custom attributes and object classes, so if one day I need to export to another directory server, I can just copy that custom created LDIF file over. (Will this work?)
    2) Create a JAVA application using JNDI. What this Java App. will do is read through a XML file and create those object classes and attributes on-the-fly. (of course, the XML structure will be predefined by me, so that my Java App. will be able to parse through it correctly. Will this work?)
    Anymore suggestion? I would want to hear more advices and suggestions.
    Also, I assume that will work even with replication. All I need to update is the master server, and the slaves will replicate automatically.
    Thank you very much! :)

    Demo: I'm using the nul character to represent the end of the word, so that the data structure can represent that "hell" and "hello" are both in the vocabulary:
    import java.util.*;
    class Node {
        private SortedMap<Character, Node> children = new TreeMap<Character, Node>();
        //0 <= index <= word.length()
        private void add(String word, int index) {
            if (index == word.length()) {
                children.put(Character.valueOf('\u0000'), null);
            } else {
                char ch = word.charAt(index);
                Node child = children.get(ch);
                if (child == null) {
                    children.put(ch, child = new Node());
                child.add(word, index+1);
        public void add(String word) {
            if (word == null || word.length()==0)
                throw new IllegalArgumentException();
            add(word, 0);
        public String toString() {
            return children.toString();
    public class Example {
        public static void main(String[] args) throws Exception {
            Node root = new Node();
            root.add("hello");
            root.add("how");
            root.add("who");
            root.add("hell");
            System.out.println(root.toString());
    }

  • Does Apple have any good way of managing iPhones for business?

    I finally broke down and allowed iPhones into our company when Apple introduced the ability to provision phones like phones (e.g. don't have to teather them to a computer to set up).  This and the "business" management tools opened the door, so we got about 30 of them.
    WHAT A HUGE MISTAKE!!!!
    Apple is now going backward.  When a phone comes into our shop, we have to load up iTunes and get the phone to sync before we can do simple things like wipe the phone or troubleshoot "why did my bluetooth quit working".  All of their "enterprise focus" seems to be around security and app control, with nothing I've seen for the day-to-day keeping things running.  (Not saying app control and secuirty are unimportant, just not enough).
    Does Apple have any good business management tools that I'm missing?  I know about MDM, but too much setup for a relatively small number of phones.  Besides, my understanding is the MDM only does app management / security policy.  Right now we use Apple's stand-alone configurator.  Fine for pushing policy and apps, but useless for troubleshooting and day-to-day management (like resetting a phone back to factory configs).
    Also, is my carrior correct that Apple will not allow them to replace phones that have gone bad under warranty?  They told me for the iPhones we have to physically take them to an Apple store for troubleshooting / replacement even after 100% identifying the issue!  That is an hour (at least) wasted to send one of my folks to the store.  I know we don't just have a bad carrior, becaue they happily send out replacement on other brands after troubleshooting over the phone.
    I actually do like the overall look/feel of the iPhones.  But unless Apple becomes much more corporate-friendly, I can only recommend that companies refuse to purchase any iDevice.  BYOD, sure...but when you buy tens or hundreds of phones stick to Android, Blackberry, or even (sorry) Microsoft based devices.

    Does not seem to work that way for us.  We plug the phone in, and the first thing iTunes does is say the phone needs to be "authorized for this computer".  It also states that the phone can only be authorized for x computers.
    It then goes through it's jig while we wait, and finally comes up with the phone.  Only then can we try to wipe / update the phone.  We do stop the sync process, that automatically starts wanting to run.  Maybe has to do with a version difference between what you use and what we use.  I did notice that an older version of iTunes seemed a bit friendlier, but would not support our iPads.
    However, when we were troubleshooting the bug where wireless / bluetooth quits working it was quite a bit more difficult than this for a phone a user handed us.  Troubleshooting steps required that the phone be "restored" in iTunes.  However, iTunes insisted on our providing a password that neither we nor the user knew.  Maybe just learning curve, but it took about an hour before we were able to get that phone to a point where we could reset it.
    Here is a sincere question for you, since you say you support a fleet of phones.  Do you really NOT get annoyed when your tech has to take a iPhone to a computer with iTunes, plug it in, and work from there whenever there is a user issue that needs to have the phone wiped back to factory standard?  This compared to being able to punch a few buttons on a different phone, right there in the users office, then hand it back to the user and say "your are fixed".
    My only assumptions are that IT staff want to solve issues as quickly and efficiently as possible.  Requireing a tech to deal with iTunes for simple procedures is not, IMHO, "as quick and efficient as possible".

  • No good way to manage podcasts

    I'd like to select the option to only keep unplayed episodes, but if I accidentally listen to a few seconds, or if I'm in the middle of one, it gets deleted when I connect to the computer.
    So I selected keep last 10 episodes. This worked great until I decided to grab a few dozen old episodes from a site I'm interested in. ZAP! - only 10 episodes show up on the Ipod. Sigh...
    So now I'm back to manually managing all my podcasts - what a drag!

    You could just set it to Keep All Episodes, then
    delete them when you are done with them...
    That's what I'm doing now. But the "perfect" solution would be for the iPod to "know" that I have listened to a track all the way to the end.
    I'm able to stop listening to a podcast, switch to something else, then later resume (most of the time) where I left off. So currently, if I decide to listen to the first bit of several podcasts, the option to "keep all unplayed episodes" is pretty worthless. And as I mentioned in the original post, I pretty much have to manage them by hand.
    Another annoyance is that if I pause in the middle of a podcast, then don't return for a couple days, the iPod shuts down. BUT when I turn it back on, it's forgotten where I left off. It resumes play either at the beginning or at the place where I previously left off.
    -Tom

  • Vim and Eclim (Java): Run Java program in embedded terminal window

    Hello all,
    I'm trying to create a decent Vim setup for Java programming. I've installed Eclim, and it works alright. However, one annoyance I have is the way that Eclim runs Java programs. When run (via the :Java command in Vim), a Java program runs in a new shell instance pretty independent from Vim, and then when the program terminates (and Enter is pressed), the output is put into a new buffer at the bottom of the Vim window with the output.
    The problem with this is that I must press Enter to go back to Vim after the program terminates, and then the output buffer is automatically selected even though I most likely do not care to copy any of the output.
    So, this is what I would like to happen:
    - I run my Java program somehow (doesn't have to be with :Java)
    - A buffer containing the running program in a shell is put on the screen (if not already there)
    - The program terminates, and the focus did not change to the output buffer
    At the very least, I want the focus to not change to the output buffer after the program is done running.
    Any ways to at least somewhat accomplish what I'm trying to  get at?

    Trent wrote:
    Yeah? I had AP CS when they first introduced the GridWorld case study. I hope you get more out of the class than I did.
    I have never used Java except for that and my first CS class at university. I eventually realized that software (as a job) wasn't for me and took a route closer to EE. I still fight to avoid being called a programmer though
    I like the idea of programming for a job, not necessarily "software development", something computer science-y sound good to me.
    But anyway, to end on an on-topic note, I embedded gvim inside Eclipse as described here.

  • How to run remote manager as a service

    Hi,
    We have remote manager installed in remote server. When we log off from the server, Remote manager stops running and our exchange provisioning fails. Is there a standard way to keep remote manager running even if we log off from the server?
    We thought of running remote manager as a window service but we are not sure whether its a good practice or not. We also, dont kow whether oracle recommends this way or not. If anybody have worked on this, then please let us know.
    Thanks.

    below link will help you to configure bat script as windows service
    http://stackoverflow.com/questions/415409/run-batch-file-as-a-windows-service
    In case of unix call your script under .profile.

  • Error while running Java Application as NT Service using INSTSRV

    Hi,
    I am trying to run Java Application as an NT Service using Instsrv.But when i start the service It works fine.when i stop the service it does not stop and it continues to run the application.When i uninstall the service It still executes.When i reboot my machine it stops .Is there any solutions for this.Any help is greatly appreciated.
    Thanks.

    I actually had similar situation. I used autoexnt.ext tool (it creats a service that can be called when rebooting) to start a batch file which in turn run a java program. After the program starts, it can only be stopped through Task Manager or Ctrl-C at the dos window (it creats a dos window) or close the window directly. Stopping the service has nothing to do with the program. I feel this is reasonable because the only function of the service here is to start the application. After that the service does not (very likely) have any connection with the program so whatever you do with the service will not affect the program itself. I wonnder if you are in the same situation.
    PC

  • A good design for a single thread pool manager using java.util.concurrent

    Hi,
    I am developing a client side project which in distinct subparts will execute some tasks in parallel.
    So, just to be logorroic, something like that:
    program\
                \--flow A\
                           \task A1
                           \task A2
                \--flow B\
                            \task B1
                            \task B2
                            \...I would like both flow A and flow B (and all their launched sub tasks) to be executed by the same thread pool, because I want to set a fixed amount of threads that my program can globally run.
    My idea would be something like:
    public class ThreadPoolManager {
        private static ExecutorService executor;
        private static final Object classLock = ThreadPoolManager.class;
         * Returns the single instance of the ExecutorService by means of
         * lazy-initialization
         * @return the single instance of ThreadPoolManager
        public static ExecutorService getExecutorService() {
            synchronized (classLock) {
                if (executor != null) {
                    return executor;
                } else {
                    // TODO: put the dimension of the FixedThreadPool in a property
                    executor = Executors.newFixedThreadPool(50);
                return executor;
         * Private constructor: deny creating a new object
        private ThreadPoolManager() {
    }The tasks I have to execute will be of type Callable, since I expect some results, so you see an ExecutorService interface above.
    The flaws with this design is that I don't prevent the use (for example) of executor.shutdownNow(), which would cause problems.
    The alternative solution I have in mind would be something like having ThreadPoolManager to be a Singleton which implements ExecutorService, implementing all the methods with Delegation to an ExecutorService object created when the ThreadPoolManager object is instantiated for the first time and returned to client:
    public class ThreadPoolManager implements ExecutorService {
        private static ThreadPoolManager pool;
        private static final Object classLock = ThreadPoolManager.class;
        private ExecutorService executor;
         * Returns the single instance of the ThreadPoolManager by means of
         * lazy-initialization
         * @return the single instance of ThreadPoolManager
        public static ExecutorService getThreadPoolManager() {
            synchronized (classLock) {
                if (pool !=null) {
                    return pool;
                } else {
                    // create the real thread pool
                    // TODO: put the dimension of the FixedThreadPool in a property
                    // file
                    pool = new ThreadPoolManager();
                    pool.executor = Executors.newFixedThreadPool(50);
                    // executor = Executors.newCachedThreadPool();
                    return pool;
         * Private constructor: deny creating a new object
        private ThreadPoolManager() {
        /* ======================================== */
        /* implement ExecutorService interface methods via delegation to executor
         * (forbidden method calls, like shutdownNow() , will be "ignored")
          // .....I hope to have expressed all the things, and hope to receive an answer that clarifies my doubts or gives me an hint for an alternative solution or an already made solution.
    ciao
    Alessio

    Two things. Firstly, it's better to use     private static final Object classLock = new Object();because that saves you worrying about whether any other code synchronises on it. Secondly, if you do decide to go for the delegation route then java.lang.reflect.Proxy may be a good way forward.

  • Running Java Programm as a Service

    i am using java service wrapper to run my program as a service
    i am getting this error i run the process by saying ./JSWrapper console
    this is my
    wrapper.conf
    # Wrapper License Properties (Ignored by Community Edition)
    # Include file problems can be debugged by removing the first '#'
    # from the following line:
    ##include.debug
    #include ../conf/wrapper-license.conf
    # Wrapper Java Properties
    # Java Application
    wrapper.java.command=/usr/java/j2sdk1.4.2_16/bin/java
    # Java Main class. This class must implement the WrapperListener interface
    # or guarantee that the WrapperManager class is initialized. Helper
    # classes are provided to do this for you. See the Integration section
    # of the documentation for details.
    wrapper.java.mainclass=jswrapper.Main
    set.JAVA_HOME=usr/java/j2sdk1.4.2_16
    # Java Classpath (include wrapper.jar) Add class path elements as
    # needed starting from 1
    wrapper.java.classpath.1=../lib/JSWrapper.jar
    wrapper.java.classpath.2=../lib/wrapper.jar
    wrapper.java.classpath.3=../lib/postgresql-8.0.309.jdbc3.jar
    # Java Library Path (location of Wrapper.DLL or libwrapper.so)
    wrapper.java.library.path.1=../lib
    # Java Additional Parameters
    #wrapper.java.additional.1=
    # Initial Java Heap Size (in MB)
    #wrapper.java.initmemory=300
    # Maximum Java Heap Size (in MB)
    #wrapper.java.maxmemory=64
    # Application parameters. Add parameters as needed starting from 1
    #wrapper.app.parameter.1=jswrapper.Main
    # Wrapper Logging Properties
    # Format of output for the console. (See docs for formats)
    wrapper.console.format=PM
    # Log Level for console output. (See docs for log levels)
    wrapper.console.loglevel=INFO
    # Log file to use for wrapper output logging.
    wrapper.logfile=../logs/wrapper.log
    # Format of output for the log file. (See docs for formats)
    wrapper.logfile.format=LPTM
    # Log Level for log file output. (See docs for log levels)
    wrapper.logfile.loglevel=INFO
    # Maximum size that the log file will be allowed to grow to before
    # the log is rolled. Size is specified in bytes. The default value
    # of 0, disables log rolling. May abbreviate with the 'k' (kb) or
    # 'm' (mb) suffix. For example: 10m = 10 megabytes.
    wrapper.logfile.maxsize=0
    # Maximum number of rolled log files which will be allowed before old
    # files are deleted. The default value of 0 implies no limit.
    wrapper.logfile.maxfiles=0
    # Log Level for sys/event log output. (See docs for log levels)
    wrapper.syslog.loglevel=NONE
    # Wrapper Windows Properties
    # Title to use when running as a console
    wrapper.console.title=Test Wrapper Sample Application
    # Wrapper Windows NT/2000/XP Service Properties
    # WARNING - Do not modify any of these properties when an application
    # using this configuration file has been installed as a service.
    # Please uninstall the service before modifying this section. The
    # service can then be reinstalled.
    # Name of the service
    wrapper.ntservice.name=testwrapper
    # Display name of the service
    wrapper.ntservice.displayname=Test Wrapper Sample Application
    # Description of the service
    wrapper.ntservice.description=Test Wrapper Sample Application Description
    # Service dependencies. Add dependencies as needed starting from 1
    wrapper.ntservice.dependency.1=
    # Mode in which the service is installed. AUTO_START or DEMAND_START
    wrapper.ntservice.starttype=AUTO_START
    # Allow the service to interact with the desktop.
    wrapper.ntservice.interactive=false
    after searching and doing google
    i decided to change wrapper.java.mainclass=jswrapper.Main
    this line to
    wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
    this line which didnt solve my problem, i am getting this error
    wrapper | JVM did not exit on request, terminated
    wrapper | JVM received a signal SIGKILL (9).
    wrapper | There were 5 failed launches in a row, each lasting less than 300 seconds. Giving up.
    wrapper | There may be a configuration problem: please check the logs.
    wrapper | <-- Wrapper Stopped

    See the Java Service Wrapper at
    http://wrapper.tanukisoftware.org/doc/english/introduction.html
    It's really good and easy to use.
    Bye.

  • To run a java service in SAP business connector.

    Hi,
    I have created one java service in SAP business connector.When i run it, i get the error as " Service 'rfctest:validatedata' is not operational. To run this service, first recompile the Java source."
    I have set the "path" variable,still i am getting the same error.
    What should i do to solve this problem?

    Hello,
    when you call a BAPI from an external system via Business Connector, you will send a bXML document to BC (for example via HTTP). Refer to the SapbcSAPAdapterGuide for how to do that in detail, its good explained (see 4-25 and 7-3) there.
    The explanation about sender/receiver is not correct. sender and receiver are the logical system names of the SAP backend system and the external system (check in transaction SALE of the SAP system).
    Just send such document to BC, it will create the routing rule automatically. Then complete the routing rule (see 7-2) and activate it.
    CSY

  • Run Java App as a Windows Service

    Hi,
    Is there an easy way (without 3rd party software) to run a Java app as a service in windows?
    Sorry if this isn't the right forum to post to...
    Any help would be greatly appreciated!
    Thanks in advance!

    Nope there isn't. And there also isn't a reason not to use 3rd party software as there is an excellent open source API to do this job: Java Service Wrapper.

  • Running Java Applications as a Windows Service

    Hi,
    can any one help me to develop windows services in java.
    Running Java Applications as a Windows Service
    Any example or link please send me.
    Thanks and regards.
    Amit.

    See the Java Service Wrapper at
    http://wrapper.tanukisoftware.org/doc/english/introduction.html
    It's really good and easy to use.
    Bye.

  • Running a java service on linux (Redhat)

    I can create a basic script to run my java service, I can stop, and restart it from the command line when logged in. I have installed the script as a service. However, when I reboot, the service will not start. I have set it to be the very last thing to start on boot-up. I'm thinking it may have something to do with the fact that when I run a java program, it does not bring me back to the command line, it just 'hangs' until it is completed, and this particular java program will obviously hang indefinitely as it is a service.
    Any help would be GREATLY appreciated.
    Thanks,
    PAUL.

    Why not start it in the background? (a trailing ampersand)
    kind regards,
    Jos

  • Is java servlet a good way for developing a website

    Hi,
    i am developing a website that has to download huge data and upload huge data .also money transactions through credit cards need to be involved.is java servlet a good way to do this or should i use an ejb or any other technology.
    Any help is appreciated.

    Thanks for the reply.But di i need to use threading of some sort or can i directly write private methods to fulfill the purpose.Also is there any way my servlet can recognise when a device is connected to a usb port of local machine
    any help is appreciated

  • Execute a .cmd file from Java program on tomcat which is running as service

    I have a .cmd/,.bat file which has to be executed depending on the parameters I pass through JSP page hosted on a tomcat instance.
    Tomcat is running as a windows service.
    I need my .cmd file to be opened in a cmd or DOS box so that user can interact with the dos window, which is mandatory.
    When I run the program from eclipse it works well but on the tomcat , the server side the output of the command is written to my log file and it gives no chance for users to monitor and interact with the command.
    Should I do something with log4j settings or is due to tomcat running as service?
    Please help.
    thanks

    thanks for the responses.
    But the design is like that.Then it needs to be fixed.
    I think this is why there's a shortage of people to write computer applications, they are all wasting their time struggling to implement bad designs.
    its a scheduler to be run on tomcat where we interact
    with the running batch files and can't be changed.A scheduler in Tomcat? Why run a scheduler in an application server?
    any help is appreciated.
    I tried to execute the batch file from servlet it
    runs , but i see the cmd.exe in windows task manager
    and need a dos box open.
    Any ideas?If you need a DOS box open then you need a signed-on user. So here's my patch:
    1. Write an application that listens for messages from this Tomcat scheduler, and when it receives those messages it does something in a DOS box.
    2. Have somebody sign on to the server and run that application.
    3. Change the Tomcat scheduler to send messages to that application instead of trying to actually run it.
    It's up to you what kind of messages you should send. There are plenty of choices.

Maybe you are looking for

  • Connecting ABAP stack of PI 7.0 to java stack of PI 7.1.

    Hi Experts, We have 2 PI servers. PI 7.0 & PI 7.1. We want to connect the ABAP stack of PI 7.0 to java stack of PI 7.1 due to some urgency and problems. What all parameters do we have to set/change. Please help Thanks in advance, ~ Suraj Can anyone p

  • Copying sapscript for printing in different language

    Hi, I need to create a sapscript which needs to be printed in 2 langauges and assigned to 2 different output types(one for english language and other for Chinese). I have already created teh sapscript for the english language and not sure how to crea

  • SPACE ITUNES IS TAKING UP ON COMPUTER HARD DRIVE

    I HAVE DOWNLOADED MY MUSIC FROM ITUNES T0 IPOD (30GB VIDEO). I AM GETTING A COMPUTER SYSTEM MESSAGE THAT I AM RUNNING LOW ON HARD DISC SPACE. IF I CLEAR MY ITUNES LIBRARY TO FREE UP SPACE, WILL IT CLEAR MY IPOD THE NEXT TIME I CONNECT?

  • MATERIAL ON ALE IDOCS

    HI CAN ANYONE GIVE ME THE MATERIAL ON ALE IDOCS......NOT JUST THE BASIC MATERIAL........I WAANT THE IN DEPTH MATERIAL...........THANKS.

  • Color Issues between CS3 and CS4

    Color Issue - Opened in CS3...looks fine; I then opened in CS4 and what was grey in CS3 is now brownish in CS4. Any ideas about what this is or how to fix?