Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3218140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:29:35+00:00 2026-05-17T15:29:35+00:00

I know ‘normal’ Java, but am new to the world of servlets, containers etc.

  • 0

I know ‘normal’ Java, but am new to the world of servlets, containers etc. Because of that I am not sure which approach is most sensible.

Situation: I have created a Servlet that receives information and stores it in a database. This database gets read by other applications.

Now what I need is an application that receives the exact same information and stores it in the same database. However this new application needs to pull this information from another server (I’ll be using httpClient for this) instead of it being pushed to it. Both applications will co-exist.

For this new applications I see the following two options:

  1. Make a stand alone application. For this I can copy paste a lot of the existing back-end code, but I will need to make some modifications (the servlet container offers a context, easy database connection pooling etc.) Further I might need to use some wrapper so this can work like a proper daemon that I can start, but also gracefully stop/restart etc.

  2. Make the new application part of a Servlet. That is: just start a new Thread in the init() of the servlet that will run the new application. This would allow me to reuse all the backend code I already have, without needing to rewrite any of it. I only need to write the code that does the HTTP-GET requests to the other server. With this approach it will also be easier to start and stop the service, because I can use the Servlet container for that.

Some info about the project: the backend code that parses and writes the data to the database has a few threads, but is not very complicated. Writing the code for the original servlet was about one week of work. With the existing code base I feel this new application should probably be 1, 2 days of work max.

The way I see it option 2 is easier. But it feels a bit like I would ‘abuse’ servlets.
So my question is: Aren’t servlets for applications that should handle requests, instead of applications that make request? Are there some huge drawbacks I don’t see here? Which option would make most sense?

tl;dr: Can I write an application that doesn’t serve requests as a Servlet?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:29:35+00:00Added an answer on May 17, 2026 at 3:29 pm

    Servlet containers are thread-managed environments. In general, don’t start your own threads in a servlet, or bad things can happen… starting and stopping the application context, for example – the appserver doesn’t know about the threads you might have started so won’t stop them with your app… (More detail in this SO question)

    I would try to extract the logic I need from the servlet into classes that don’t depend on the Servlet API, and redesign the servlet to make use of these classes. (Refactoring). The servlet API, as you note, is all about receiving requests and sending responses.

    I can re-use the logic in my new non-servlet classes anywhere I like, including a non-servlet part of the application that polls out pull that info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

know nothing about php, but I have this script that reads a folder and
I know similar questions have been posted before, but I have specific requirements that
I know this is a silly doubt but I just want to make sure
Know of an OCAML/CAML IDE? Especially one that runs on Linux?
I know that I can do something like $int = (int)99; //(int) has a
I know this might be a no-brainer, but please read on. I also know
I know, I would have thought the answer was obviously no as well, but
I know there is a registry key indicating the install directory, but I don't
I know I must be missing something, but in a while statement how does
Know of a way to mock %[]? I'm writing tests for code that makes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.