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 404151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:16:55+00:00 2026-05-12T17:16:55+00:00

I’m not exactly sure what question to ask here since I don’t know the

  • 0

I’m not exactly sure what question to ask here since I don’t know the vocabulary…

Tomcat servlets (and any server for that matter) work nicely if they are stateless and respond quickly to requests, with state stored in a database. It seems like if I have long-running operations then maybe I want to run some other service in the background, and have the Tomcat handlers communicate with it. Is there a way to run a long-running Java application in the same JVM as Tomcat and interact with it via “regular” Tomcat servlet?


Example: Let’s say I want to offer a RESTful number factorization service in HTTP.

Here’s a possible scenario (I hope I have the HTTP syntax right, I’m omitting most of the headers):

# comments start with #, > = request, < = response
# 
# first we create a queue
> POST /factorizer/create-queue
> {information here}
< queue=12345B
# then we post some numbers to it
> POST /factorizer/queue/12345B
> 123
> 456
> 678
> 12345678901234567890123456789
< OK
# let's look at the status
> GET /factorizer/queue/12345B/status
< requested=4
< processed=3
# query
> GET /factorizer/queue/12345B/7
< Error: invalid index
> GET /factorizer/queue/12345B/3
< Error: not complete
> GET /factorizer/queue/12345B/0
< 123=3*41
# wait a while
> GET /factorizer/queue/12345B/status
< requested=4
< processed=4
> GET /factorizer/queue/12345B/3
< 12345678901234567890123456789=3*3*3*7*13*31*37*211*241*2161*3607*3803*2906161

I can think of how to write the servlet to handle the queries, but how could I go about implementing a daemon / independently-running service in the same JVM?

edit: In the above example, what I would like to do is to have a background application that runs autonomously, with work queues, to factor prime numbers, and has a Java interface that supports the operations that the Tomcat servlets could use to expose the service to the web. Then I don’t have to worry about the web interface or HTTP in my background app, and I don’t have to worry about multithreading issues or prime factorization in my servlets.

  • 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-12T17:16:55+00:00Added an answer on May 12, 2026 at 5:16 pm

    If you don’t absolutely need to be in the same JVM (that is, if you don’t need the performance of directly accessing the objects) you could write another Tomcat application and have your other apps communicate with it by HTTP to localhost. In effect you would be writing a web service that happens to run on the same machine. (I don’t know how else multiple Tomcat applications can see each other. This is a problem that Enterprise Java Beans solves, but that may be too heavyweight a solution for you.)

    If you have only a single Tomcat application that needs to do this, create a worker thread and put it in the application context where all the requests can communicate with it.

    With regard to your specific problem, it looks like you are describing something like the Asynchronous Job pattern in the O’Reilly “Restful Web Services” book. This uses the “202 Accepted” status code to indicate that the processing is not complete. See “Asynchronous Operations” in Chapter 8 of the book.

    http://www.amazon.com/RESTful-Web-Services-Leonard-Richardson/dp/0596529260/ref=sr_1_1?ie=UTF8&s=books&qid=1255555328&sr=8-1

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

Sidebar

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want use html5's new tag to play a wav file (currently only supported
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
I'm looking for suggestions for debugging... If you view this site in Firefox or
I am currently running into a problem where an element is coming back from
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
In order to apply a triggered animation to all ToolTip s in my app,

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.