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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:33:30+00:00 2026-05-26T08:33:30+00:00

NumberFormat JavaDoc says: Number formats are generally not synchronized. It is recommended to create

  • 0

NumberFormat JavaDoc says:

Number formats are generally not synchronized. It is recommended to create separate format instances for each thread.

I want to obtain an instance to use in my objects. One instance per thread, or one instance per Object (objects are not shared among threads). At the moment the object has an instance variable containing NumberFormat.

private NumberFormat nFormat = NumberFormat.getInstance(Locale.ITALY);

This is already fine, I shouldn’t have any race condition, since Objects are not shared.

However, I don’t know how to use Spring to configure this, I know about factory-method, but I don’t know how to pass a Locale to it.

<bean factory-method="getInstance" class="java.text.NumberFormat" 
    scope="prototype" />

How to declare my NumberFormat bean properly?

  • 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-26T08:33:31+00:00Added an answer on May 26, 2026 at 8:33 am

    This is how you could do it:

    <bean id="numberFormat" factory-method="getInstance"
          class="java.text.NumberFormat" scope="prototype">
        <constructor-arg>
            <util:constant static-field="java.util.Locale.ITALY" />
        </constructor-arg>
    </bean>
    

    However, I probably wouldn’t use Spring at all to do it, I’d use a static factory method instead.

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

Sidebar

Related Questions

I know that SimpleDateFormat and NumberFormat are NOT thread safe. https://bugs.java.com/bugdatabase/view_bug?bug_id=4101500 But what about
Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol = $; decimal value = 500; Trace.TraceInformation({0:C}, value); Trace.TraceInformation(string.Format({0:C}, value)); produces the following
When registering a customerEditor in spring to format a number with a given numberFormat
I am trying to create a NumberFormat that will not use Groups at all.
In rml reports how can i change the current page number format from page:1
How can I convert an Excel date (in a number format) to a proper
I'm using NumberFormat.getCurrencyInstance().format(amount) to format currency from a BigDecimal to a string. This works
I have the following code : NumberFormat nf=NumberFormat.getInstance(Locale.FRANCE); nf.setMinimumFractionDigits(3); String s= nf.format(3456.32); // double
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.UK); BigDecimal b = new BigDecimal(10); System.out.println (String.format(Data %s, nf.format(b.doubleValue()))); This
Getting an NumberFormat exception from a form submission that passes a phone number. However,

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.