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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:50:18+00:00 2026-05-11T18:50:18+00:00

class ApplicationContext{ private final NetworkObject networkObject = new networkObject(); public ApplicationContext(){ networkObject.setHost(host); networkObject.setParams(param); }

  • 0
class ApplicationContext{
    private final NetworkObject networkObject = new networkObject();

    public ApplicationContext(){
      networkObject.setHost("host");
      networkObject.setParams("param");
    }

    public searchObjects(ObjectType objType){
        networkObject.doSearch(buildQuery(objType));
    }
}

class NetworkObject{
    private final SearchObject searchObject = new SearchObject();

    public doSearch(SearchQuery searchQuery){
        searchObject.search(searchQuery); //threadsafe, takes 15(s) to return
    }
}

Consider a webserver running a web application which creates only one ApplicationContext instance (singleton) and uses the same applicationInstance to call searchObjects e.g.

 ApplicationContext appInstance = 
                  ApplicationContextFactory.Instance(); //singleton

Every new request to a webpage say ‘search.jsp’ makes a call

 appInstance.searchObjects(objectType);

I am making 1000 requests to ‘search.jsp’ page. All the threads are using the same ApplicationContext instance, and searchObject.search() method takes 15 seconds to return. My Question is Do all other threads wait for their turn (15 sec) to execute when one is already executing the searchObject.search() function or All threads will execute searchObject.search() concurrently, Why??

I hope I have made my question very clear??

Update:
Thanks all for clarifying my doubt. Here is my second Question, what difference in performance should be observe when I do:

public synchronized doSearch(SearchQuery searchQuery){
    searchObject.search(searchQuery); //threadsafe, takes 15(s) to return
}

OR

public doSearch(SearchQuery searchQuery){
    searchObject.search(searchQuery); //threadsafe, takes 15(s) to return
}

I believe using the function ‘doSearch’ without synchronized keyword should be giving more performance. But, when I tested it today, the results came out the other way. The performance was similar or sometimes better when I use synchronized keyword.

Can anyone explain the behavior. How should I debug such cases.

Regards,

Perry

  • 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-11T18:50:18+00:00Added an answer on May 11, 2026 at 6:50 pm

    Well you haven’t specified any synchronization in the code, so without any other evidence I’d suspect that all the threads will run concurrently. If SearchObject.search contains some synchronization though, that would obvious limit the concurrency.

    Mind you, your JSP container is probably using a thread pool to service the 1000 requests, rather than creating 1000 threads.

    EDIT: As for why it may be faster with synchronized: sometimes concurrency isn’t actually helpful to throughput. Things like context switching, disk bottlenecks, cache misses etc have that effect. It’s usually not a good idea to have more running threads than cores.

    For a real-life example, suppose you have a thousand shoppers who all want to buy things from a fairly small shop. How would you go about it? Put all 1000 in the shop at the same time, or keep it down to a fairly small number in the shop at any one time, and a queue outside?

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

Sidebar

Ask A Question

Stats

  • Questions 202k
  • Answers 202k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I tried using the nr parameter, without any luck. I… May 12, 2026 at 8:19 pm
  • Editorial Team
    Editorial Team added an answer LinearLayout is a box layout - I can actually see… May 12, 2026 at 8:19 pm
  • Editorial Team
    Editorial Team added an answer My favorite is Squirrel SQL. Works well, simple to set… May 12, 2026 at 8:19 pm

Related Questions

When trying to start my JUnit-Test out of Eclipse, I get a ClassNotFoundException. When
I have a class which constructor takes a Jakarta enums . I'm trying to
I'm brand spanking new at Spring and have gotten a majority of the knowledge
I am using the below function to Close existing form and opening new form.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.