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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:54:17+00:00 2026-05-30T16:54:17+00:00

I have a class which acts as a simple crawler and I want to

  • 0

I have a class which acts as a simple crawler and I want to invoke this class within a servlet.

My idea is to get an url from user then url request will be passed to the servlet and servelt pass the url to the class and class will start the crawling. and I want my servlet to create only one instance of this class.the retrieved data from crawlwer will be added to the DB directly by the class.
I want to control the behavior of the class like running/halting/stopping from servlet
(for this matter I think I am able to create a simple xml file which will be shared between servlet and class and if servlet change the status code class should response to the status change)

But I have some doubts about how to control the behavior of the class such as command it to run/halt/stop and since my class is not multithreaded I don’t have any idea what will happen to invoked class after calling it from servlet and since this class needs to read from network obviously I’ll have some gap/freezing phase during running it.

How can I solve the problem of concurrency in this situation?or in other word will I have any concurrency issue or not?

regards.

  • 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-30T16:54:18+00:00Added an answer on May 30, 2026 at 4:54 pm

    It depends on the Servlet container you are using. Some containers spawn a new Thread per user request (almost always this is the desired behavior), so you should definitely design for concurrency.

    You can make the Servlet class implement SingleThreadModel, then in the service method you can directly call the crawler class code, as only a thread will enter service at a time.

    This implies only an URL can be processed at a given time, which is probably not what you want, so instead of that, don’t implement SingleThreadModel and create a singleton executor service in the init method:

    ExecutorService ex = Executors.newFixedThreadPool(20); //Only 20 tasks at a given time
    

    Then, in the service method create a new CrawlingTask (Runnable) with the URL specified in the request, then submit the task to the executor.

    That way you could also shutdown it:

    ex.shutdown();
    

    As ExecutorService is thread-safe, you don’t have to worry about concurrency when enqueuing tasks.

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

Sidebar

Related Questions

I have an abstract base class which acts as an interface. I have two
I have class A which extends the Activity class. This class is in package
I have class Employee which is something like this. class Emp { int EmpID;
I have a class which is marked with a custom attribute, like this: public
I have a class which contains a static field that acts like a singleton
I have an class library called ServiceLayer which acts as a repository for a
I have a class called 'Article' in a project called 'MyProject.Data', which acts as
I have this code for login validation using a Struts2 action class which calls
I have class which have one public method Start , one private method and
I have class Money which is an @Embeddable @Embeddable public class Money implements Serializable,

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.