Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet to control threads  RSS feed

 
Chris Oglethorpe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am thinking of using a servlet to remotely control a server.

What I want is a servlet that can be called to launch a server as a thread. I want the thread to stay alive after the servlet runs, and be killed when another call comes into the servlet. Is that kind of behaviour possible with servlets?

If not, I might try and have the servlet launch a seperate process, but I thought the threaded approach might give more control.
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the purpose of this server that you want to launch using a servlet?

What do you run the servlet in? Tomcat or some other application server?
That means you have to keep the application server and the servlet running at all times, so you can call the servlet to start/stop the other server process.
Is that what you had in mind?
 
Chris Oglethorpe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sonny Gill:
What is the purpose of this server that you want to launch using a servlet?

What do you run the servlet in? Tomcat or some other application server?
That means you have to keep the application server and the servlet running at all times, so you can call the servlet to start/stop the other server process.
Is that what you had in mind?


I want to run the servlet under Tomcat. I understand that the Tomcat server will always have to run, but I plan on keeping it running anyway. What I'm not sure of is how to keep the threads active but still let the servlet receive requests.

The idea is that the servlet acts as a master thread and spawns multiple slave threads that it can manage.
 
Yong Bakos
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer your question, yes, that sort if behavior is possible with Servlets. But you may want to think about this design a bit.

Keep in mind that letting your first session die after the server is instantiated in its thread will require you to figure out a way for another servlet request to get a reference to your server in order to manipulate it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!