Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: How do confirm the tomcat process running state from the Java Code

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do confirm the tomcat process running state from the Java Code

    Hi,

    I started the tomcat-8.5 in standalone mode (as a windows process) using stratup.bat and I wanted to confirm that the tomcat process is running or not from my java code.
    Please suggest me a solution for finding the tomcat process from the java code.


    Thank you

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,668
    Thanks
    52
    Thanked 2,320 Times in 2,276 Posts

    Default Re: How do confirm the tomcat process running state from the Java Code

    Is it a server that can be connected with?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do confirm the tomcat process running state from the Java Code

    My java code is a standalone program having main() and the tomcat server is started from the same.
    Here I need to know that the server is stared or not?

    Thank you

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,668
    Thanks
    52
    Thanked 2,320 Times in 2,276 Posts

    Default Re: How do confirm the tomcat process running state from the Java Code

    Can you use a socket to connect to the server and ask it what it is doing?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do confirm the tomcat process running state from the Java Code

    Thank you for the reply,
    In my case I wanted to know with process name instead of socket to connected.

    --- Update ---

    In existing application I am using below code to know the tomcat running state,

    Existing code with java-8: tools.jar
    import sun.jvmstat.monitor.MonitoredHost;
    import sun.jvmstat.monitor.MonitoredVm;
    import sun.jvmstat.monitor.MonitoredVmUtil;
    import sun.jvmstat.monitor.VmIdentifier;

    // procName = “Bootstrap”
    /**
    * Confirm startup of server process
    * Obtain process information of JavaVM and check whether specified startup class is running
    * true: Starting / false: not running
    */
    private static boolean checkServerProcess(String procName) {
    boolean blRet = false;
    try {
    MonitoredHost host = MonitoredHost.getMonitoredHost("localhost");
    for (Object processId : host.activeVms()) {
    MonitoredVm vm = host.getMonitoredVm(new VmIdentifier("//" + processId + "?mode=r"));

    if(MonitoredVmUtil.mainClass(vm, true).contains(procName)) {
    blRet = true;
    break;
    }
    }
    } catch(Exception e) {
    blRet = false;
    }
    return blRet;
    }


    but now I am using Java-11 and we wanted to do same without tools.jar


    thank you

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,668
    Thanks
    52
    Thanked 2,320 Times in 2,276 Posts

    Default Re: How do confirm the tomcat process running state from the Java Code

    Sorry, I've never used classes from the tools.jar file.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do confirm the tomcat process running state from the Java Code

    Thank you,

    Is there any other way to do the same without using tools.jar classes.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,668
    Thanks
    52
    Thanked 2,320 Times in 2,276 Posts

    Default Re: How do confirm the tomcat process running state from the Java Code

    do the same
    I don't know anything about asking an OS about what other programs are running. That is not a normal question for a java program.
    Is there an OS program that could be called from the java Runtime class and then read and parse its response?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. java code for a cement making process
    By sandyman918 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 19th, 2018, 06:56 AM
  2. Display number of threads in each running process
    By Waseem Usman in forum Threads
    Replies: 1
    Last Post: March 23rd, 2012, 10:51 AM
  3. getting NPException while running my struts first application using tomcat
    By rafishaik999 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: September 19th, 2011, 06:56 AM
  4. Replies: 1
    Last Post: May 25th, 2011, 08:55 AM
  5. Problem running Apache tomcat 6.0 using i.p. address
    By nakul in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: April 8th, 2010, 08:58 AM

Tags for this Thread