0

I wanna use an embedded Tomcat V6. The code works perfectly, but only as long as the programm is running. So if there is no Thread.Sleep it will exit immediately, otherwiese keep on running till the time is up.

How can I keep the emmbedded Tomcat alive. setAwait(true) should deal with this, shouldn't it? But i does not work. Tried to figure out more about this, but there is nothing in the description. Any other ideas?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Chris
  • 1
  • I haven't used Tomcat embedded, but used Jetty several times. Jetty is purpose-built to be embedded, and if you don't have special performance or configuration requirements, it should do pretty well instead of Tomcat. – Miklos Csuka Aug 23 '10 at 14:10
  • Can you show some code where you start Tomcat ? – PeterMmm Aug 23 '10 at 14:13
  • heard that too, but i am forced to use tomcat because i am told to use it, and only it – Chris Aug 23 '10 at 14:15
  • it is pretty much the same as the example: http://stackoverflow.com/questions/640022/howto-embed-tomcat-6, i am still testing. as i said, it works, but the programm comes to an end and so the server does – Chris Aug 23 '10 at 14:18

2 Answers2

0

If you want your embedded Tomcat to run indefinitively you will need some code to handle outside administrative requests (like restart, shutdown, stuff like that). That will go in your main thread, incidentially keeping the Tomcat instance alive.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • I don't see how this is going to solve my problem. The main methode is starting the thread. The run methode sets up the embedded as in the link above. But when the set up is completed, the programm comes to an end and so does the server. For sure I need shutdown and restart methodes but as long as the server doesn't stay alive is this my major problem – Chris Aug 24 '10 at 07:25
  • The main thread should not come to an end, but wait for commands from "somewhere". – Thorbjørn Ravn Andersen Aug 24 '10 at 09:47
  • yeaaaaaaaaaaaaah and thats the point i do not know how to do! How can I make the mainthread wait for commands??? just myThread.wait caueses an exception and i don't wanna make while(true){ Thread.sleep(10000);} – Chris Aug 24 '10 at 12:30
0

This class should do what you are looking for.

Benjamin Muschko
  • 32,442
  • 9
  • 61
  • 82