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

  • Home
  • SEARCH
  • 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 7018875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:06:32+00:00 2026-05-27T23:06:32+00:00

Is there any point in having a constructor in a Java Web Service class?

  • 0

Is there any point in having a constructor in a Java Web Service class? (There seems to be no consensus in the articles I have found so far.)

I am using Jersey to implement a REST web service that needs to have a non-static common object (a string-processing utility class) made available to various (non-static) methods of the service.

Initializing this common object would typically happen in the constructor of the class, if that were not a web service. But what about now that it is?

If a constructor cannot be used, should I put, in every relevant method, a synchronized block that checks whether the common object is available and, if not, initialize it? Or is there a better approach?

  • 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-27T23:06:32+00:00Added an answer on May 27, 2026 at 11:06 pm

    Every web service class does have a constructor. If you don’t include one then Java automatically adds the default no-arg constructor for you. You can:

    1. Initialize the utility instance when declaring it’s class variable
    2. Manually add the default constructor and initialize the utility
      instance in it
    3. Or if your using JEE6 you can inject the utility instance into your
      web service
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any point to freeing memory in an atexit() function? I have a
Is there any problem in initializing Sets in the constructor of a class persisted
Is there any point in having a com.myco.myproj.MyProjRuntimeException, which completley extends RuntimeException?
is there any point in having a robots.txt with just one line of content
Is there any way to print an OOXML document (.docx file) without having MS
Are there any free libraries that would print to a PDF without actually having
Would there be any point in adding resx files to a distributed cache? What
Is there any way to get the local end point of a connected Silverlight
Is there any comparison to show why JSP/ASP.Net is better from security point of
Is there any way to rotate a disclosure button? I'd like it to point

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.