Init method in servlet freezing the servlet

Discussion in 'Java' started by Mitch, Mar 13, 2006.

  1. Mitch

    Mitch Guest

    I have already posted this query, although it was appended to one of my
    threads with a different subject so if you have read this already I
    apologise.

    Rather than paste the whole thing over there is a link here to my
    question
    http://groups.google.com/group/comp.../fa1385d4fb472da7?tvc=1&#doc_2eb2277394b9a908

    It pans out that I have a servlet which is calling an init method when
    first invoked. However once the init method is called the servlet no
    longer functions normally (It doesn't print like it is supposed to for
    example) This means that I can not display within the System it
    initialises any information about the system. I can't use a different
    servlet either as this does not have permission to access the system.

    I have found that this problem is also caused when the contents of the
    init method are also used in the main methods of the servlet, however
    they are best suited to the init method.

    Here you can see that the init method is very simple

    ///////////////////////////////////
    ////////

    public void init(ServletConfig config)
    throws ServletException
    {
    super.init(config);

    RSS = new RailSimulationSystem();

    RSS.run();

    }

    ////////////
    //////////////////////////////////////

    I wonder if it is because I am starting a thread?

    the RSS object is initiated as I have the system println'ing to tell me
    so.


    Any ideas on what is going on which might cause this behaviour are
    greatly appreciated.

    Kind Regards,

    Mitch.
    Mitch, Mar 13, 2006
    #1
    1. Advertising

  2. Mitch

    Timo Stamm Guest

    Mitch schrieb:
    > [...] once the init method is called the servlet no longer
    > functions normally [...]
    >
    > public void init(ServletConfig config) throws ServletException {
    > super.init(config);
    > RSS = new RailSimulationSystem();
    > System.out.println("a");
    > RSS.run();
    > System.out.println("b");
    > }
    >
    > I wonder if it is because I am starting a thread?


    Are you sure you are starting a new thread? You have to either extend
    Thread or implement Runnable and use new Thread(Runnable).

    If the code above doesn't print "b" immediately after printing "a", you
    are not starting a new thread.


    Timo
    Timo Stamm, Mar 13, 2006
    #2
    1. Advertising

  3. Mitch

    Mitch Guest

    Timo Stamm wrote:
    > Mitch schrieb:
    >> [...] once the init method is called the servlet no longer functions
    >> normally [...]
    >>
    >> public void init(ServletConfig config) throws ServletException {
    >> super.init(config);
    >> RSS = new RailSimulationSystem();
    >> System.out.println("a");
    >> RSS.run();
    > > System.out.println("b");
    >> }
    > >
    >> I wonder if it is because I am starting a thread?

    >
    > Are you sure you are starting a new thread? You have to either extend
    > Thread or implement Runnable and use new Thread(Runnable).
    >
    > If the code above doesn't print "b" immediately after printing "a", you
    > are not starting a new thread.
    >
    >
    > Timo


    That is incredibly infuriating.

    I am not printing b after I am printing a.
    I am A) terribly grateful and B) ****ing furious. Sometimes you can't
    see past the end of your nose. I am calling run on a Runnable object.
    I should be making a new Thread and then Thread.starting it to make it
    go. !"£$%^&*().

    Thank you. I had println's and breakpoints everywhere but where I
    needed them, right where I knew the problem was.

    Well that solved it, thank you. I honestly don't know how long it would
    have taken me, which is half of why I am so peeved.

    Thank you very much!

    Mitch.
    Mitch, Mar 13, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony Cheng
    Replies:
    1
    Views:
    8,205
    Juan T. Llibre
    Feb 24, 2006
  2. Stephan Koser
    Replies:
    3
    Views:
    28,381
  3. Replies:
    1
    Views:
    656
    Jules
    Aug 18, 2005
  4. Jess
    Replies:
    4
    Views:
    438
  5. news.aon.at
    Replies:
    11
    Views:
    640
    Ian Collins
    Jan 29, 2011
Loading...

Share This Page