Is there a thread safe date format ?

I had format problem with date so I wrote a test program to see if I could reproduce it
this program runs 2 threads which translate a system date into a french date format
I used 3 method
1 - static java.text.DateFormat df = �����������������DateFormat.getDateInstance(DateFormat.SHORT,Locale.FRANCE);
the result is
thread 1 �04/02/02
thread 1 �04/02/02
thread 1 �04/02/02
thread 2 �04/02/02
thread 1 �04/02/2002 � ==> ?
thread 2 �04/02/02
thread 1 �04/02/2002 �==> ?
thread 2 �04/02/02
thread 1 �04/02/2002 �==> ?
thread 2 �04/02/02
thread 1 �04/02/2002
2 - static java.text.DateFormat df = ��������������DateFormat.getDateInstance(DateFormat.LONG,Locale.FRANCE);
thread 2 �4 f�vrier 2002
thread 2 �4 f�vrier 2002
thread 2 �4 f�vrier 2002
thread 2 �4 f�vrier 2002
thread 1 �0004 f�vrier 2002 �==> ?
thread 1 �4 f�vrier 2002
thread 1 �4 f�vrier 2002
3 - �SimpleDateFormat ("dd/MM/yyyy");
thread 2 �04/0002/2002 ==> ?
thread 1 �04/02/2002
thread 2 �04/0002/2002 ==> ?
thread 1 �04/02/2002
thread 2 �04/0002/2002 ==> ?
thread 1 �04/02/2002
thread 1 �04/02/2002
did I miss something ?
why it is not "thread safe " ?
any help ...
thranks denis
(my sample program)
import java.util.*;
import java.text.*;
public class th extends Thread {
/** T1 = getDateInstance(DateFormat.[SHORT-LONG],Locale.FRANCE); **/
//static java.text.DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT,Locale.FRANCE);
/** T2 = SimpleDateFormat **/
static private SimpleDateFormat _formatter = new SimpleDateFormat ("dd/MM/yyyy");
public String message ;
public th (String msg) {
this.message = msg ;
public void run () {
try {
while ( true ) {
printmess() ;
} catch (Exception e ) {System.out.println (" error  ") ; } ;
public void printmess( ) {
     /** T1 **/
     //String dateString = df.format(new Date());
     /** T2 **/          
String dateString = _formatter.format( new Date() );
System.out.println(message+" "+dateString);
public static void main(String[] args) {
Thread t1 = new th("thread 1 ") ;
Thread t2 = new th("thread 2 ") ;
t1.start();
t2.start();

I was able to reproduce your problem and found that make a minor change seems to have fixed the problem:
import java.util.*;
import java.text.*;
public class th extends Thread {
/** T1 = getDateInstance(DateFormat.[SHORT-LONG],Locale.FRANCE); **/
//static java.text.DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT,Locale.FRANCE);
/** T2 = SimpleDateFormat **/
// static private SimpleDateFormat _formatter = new SimpleDateFormat ("dd/MM/yyyy");
SimpleDateFormat _formatter;
public String message ;
public th (String msg) {
this.message = msg ;
_formatter = new SimpleDateFormat ("dd/MM/yyyy");
public void run () {
try {
while ( true ) {
printmess() ;
} catch (Exception e ) {System.out.println (" error ") ; } ;
public void printmess( ) {
/** T1 **/
//String dateString = df.format(new Date());
/** T2 **/
String dateString = _formatter.format( new Date() );
System.out.println(message+" "+dateString);
public static void main(String[] args) {
Thread t1 = new th("thread 1 ") ;
Thread t2 = new th("thread 2 ") ;
t1.start();
t2.start();
V.V.

Similar Messages

  • Problem with date format when ask prompt web-intelligence

    Bo XIR2 with 5 SP. Instaled on Windows 2003 with support Russian.
    Inside BO every labels, buttons - use russian. But when invoke web-report and Prompt appear there is problem with date format.
    Looks like korean format of date 'jj.nn.aaa H:mm:ss'.  I see system settings of date in Win .. everything right
    What i have to do?
    Where i can change format date for bo?

    GK, try this...
    decode(instr(packagename.functionname(param1 ,param2),'2400'), 0, to_date(to_char(to_date(rtrim(packagename.functionname(param1 ,param2),'(PT)'), 'Month dd, yyyy "at" hh24mi'),'mm/dd/yyyy hh24mi'),'mm/dd/yyyy hh24mi'),
                                                                      to_date(to_char(to_date(rtrim(packagename.functionname(param1 ,param2),'(PT)'), 'Month dd, yyyy "at" "2400"')+1,'mm/dd/yyyy "0000"'),'mm/dd/yyyy "0000"'))-Marilyn

  • Date format in Finder

    Swedish Leopard 10.5.2
    In the Finder's list view, is it possible to alter the date format shown? In the system settings, there are 4 different date strings available to alter (I don't want to start by altering them if I don't need to). Loosely translated from Swedish, they are called "Short", "Normal", "Long" and "Full".
    Finder displays the "Full" date format, followed by the time. I would like to change this to display the "Short" date format instead. Is this possible somehow? I know I can turn off showing dates as "Yesterday" and such, but that is NOT what I'm after. I want to display the date as set by the "Short" date format in the system settings.
    Is this possible to somehow achieve with some "defaults write" command in the terminal? I am new to OS X, but not afraid to fiddle with things like this.
    Thanks for any response on this.

    There are four different date formats in International, System preferences.
    The Finder seems to use all of these depending on the width of the time column.
    I myself don't like the appearance of the date and time changing with the width of a column.
    In particular I don't like the date with names for months; it's annoying for comparison.
    The only way to always get the same date/time in list view of the Finder is to make all date formats
    (short,medium,long,full) the same. That's what I have done and now I have what I want.
    It won't win a beauty contest.

  • CalendarUI element showing different date format for different locations

    Hi,
    I have an input field with date calendar in my webdynpro Java form . User can select date from this calendar and fill the input field. For this I have used input field  in my layout and have binded this with one context attribute of type date. Say name of this field is requiredByDate
    Now when I build and deploy my code, I can see the the required By date field and user is able to select date values from the calendar button next to the input field. The format of the date selected is mm/dd/yyyy.
    However , when a user tests this application from other location say Malaysia, for him the format is coming as dd/mm/yyyy after selecting the date from the calendar.
    Just want to know ,is there is difference in date format for differnt locations ? For India, when you select the date its showing mm/dd/yyyy and for Malayisa its showing dd/mm/yyyy.
    Is there anything we can do by changing our system settings like timezone or dateformat in system settings.
    I am using standard UI element and binding it with context element of type date.
    Need your advice or help on this..
    Thanks and regards,
    Sai

    Hi,
    go to
    [http://help.sap.com/saphelp_nw04/helpdata/en/f4/d95664da179b4db731e21c2e470b72/frameset.htm|http://help.sap.com/saphelp_nw04/helpdata/en/f4/d95664da179b4db731e21c2e470b72/frameset.htm]
    It describes the fallback sequence followed by the Web Dynpro for Java Runtime in order to determine the current session locale.
    Regards
    Matteo

  • Changing Date format from MM/DD/YYYY to DD/MM/YYYY

    Hello all,
              We have upgraded our portal system from EP 6.0 to EP 7.0 . Before upgrade the portal date format was in DD/MM/YYYY  format but after upgrade it has changed to MM/DD/YYYY.
              We changed the request.mandatoryCountry and Request.mandatoryLanguage parameters as GB and EN respectively .
    After this change the standard portal iview start showing date in DD/MM/YYYY format but custom web dynpro applications are still displaying date in MM/DD/YYYY format.
            Please suggest how can we change the date format for custom dynpro applications too.
    Regards,
    Ganesh

    Ganesh,
    You might find [this|http://help.sap.com/saphelp_nw04/helpdata/en/f4/d95664da179b4db731e21c2e470b72/frameset.htm] link helpful in understanding how the locale is determined for a user who logs into the portal.
    Similar discussions are on the following threads
    1 - date format
    2 - internationalization problem - default language of wd in portal
    A snippet from the above thread,
    1) Language indicator of the user  (Example: Language not set in portal)
    2) Language preference of the browser (Example: fr - Resource doesn't exists)
    3) Language indicator of the Web Dynpro Application
    4) Language preference of the system
    5) Language preference of the JVM
    Hope it helps.
    Good Luck!!!
    GLM

  • F:convertDateTime - how to define two valid date formats?

    I have an input field that accepts a date. There are two valid date formats allowed: yyyyMMdd & yyyyMMM
    I am currently doing this ...
    <h:inputText ...>
    <f:convertDateTime pattern="yyyyMMdd" />
    <f:convertDateTime pattern="yyyyMMM" />
    </h:inputText>
    ... but only the second date format is being accepted as valid.
    How can I specify two valid date formats for the input?
    Thanks,
    rh
    Edited by: user13328234 on Oct 27, 2010 12:47 PM

    user13328234 wrote:
    Thanks for the suggestion. I was actually using it for validation, so I implemented a custom validator so I'm good now.
    But, for some reason I expected it to work with two converters specified, and I'm a little disappointed it didn't work.
    Thanks again,
    rhExpecting = assuming. Its getting old and annoying now, but it remains a very bad idea.
    The fact of the matter is that you have a very specific need. There is only one way to tailor to specific needs in a generic API: allow to override default behavior. The other option is to create a bloated API that tries to incorporate so many bells and whistles that it becomes unusable. So in my opinion, JSF is designed exactly the way it is supposed to be in this respect.

  • SSRS - Is there a multi thread safe way of displaying information from a DataSet in a Report Header?

     In order to dynamically display data in the Report Header based in the current record of the Dataset, we started using Shared Variables, we initially used ReportItems!SomeTextbox.Value, but we noticed that when SomeTextbox was not rendered in the body
    (usually because a comment section grow to occupy most of the page if not more than one page), then the ReportItem printed a blank/null value.
    So, a method was defined in the Code section of the report that would set the value to the shared variable:
    public shared Params as String
    public shared Function SetValues(Param as String ) as String
    Params = Param
    Return Params 
    End Function
    Which would be called in the detail section of the tablix, then in the header a textbox would hold the following expression:
    =Code.Params
    This worked beautifully since, it now didn't mattered that the body section didn't had the SetValues call, the variable persited and the Header displayed the correct value. Our problem now is that when the report is being called in different threads with
    different data, the variable being shared/static gets modified by all the reports being run at the same time. 
    So far I've tried several things:
    - The variables need to be shared, otherwise the value set in the Body can't be seen by the header.
    - Using Hashtables behaves exactly like the ReportItem option.
    - Using a C# DLL with non static variables to take care of this, didn't work because apparently when the DLL is being called by the Body generates a different instance of the DLL than when it's called from the header.
    So is there a way to deal with this issue in a multi thread safe way?
    Thanks in advance!
     

    Hi Angel,
    Per my understanding that you want to dynamic display the group data in the report header, you have set page break based on the group, so when click to the next page, the report hearder will change according to the value in the group, when you are using
    the shared variables you got the multiple thread safe problem, right?
    I have tested on my local environment and can reproduce the issue, according to the multiple safe problem the better way is to use the harshtable behaves in the custom code,  you have mentioned that you have tryied touse the harshtable but finally got
    the same result as using the ReportItem!TextBox.Value, the problem can be cuased by the logic of the code that not works fine.
    Please reference to the custom code below which works fine and can get all the expect value display on every page:
    Shared ht As System.Collections.Hashtable = New System.Collections.Hashtable
    Public Function SetGroupHeader( ByVal group As Object _
    ,ByRef groupName As String _
    ,ByRef userID As String) As String
    Dim key As String = groupName & userID
    If Not group Is Nothing Then
    Dim g As String = CType(group, String)
    If Not (ht.ContainsKey(key)) Then
    ' must be the first pass so set the current group to group
    ht.Add(key, g)
    Else
    If Not (ht(key).Equals(g)) Then
    ht(key) = g
    End If
    End If
    End If
    Return ht(key)
    End Function
    Using this exprssion in the textbox of the reportheader:
    =Code.SetGroupHeader(ReportItems!Language.Value,"GroupName", User!UserID)
    Links belowe about the hashtable and the mutiple threads safe problem for your reference:
    http://stackoverflow.com/questions/2067537/ssrs-code-shared-variables-and-simultaneous-report-execution
    http://sqlserverbiblog.wordpress.com/2011/10/10/using-custom-code-functions-in-reporting-services-reports/
    If you still have any problem, please feel free to ask.
    Regards
    Vicky Liu

  • Hashtable really thread safe or is there a bug in it ?

    Hashtable is said to be thread-safe, so I think it should be true.
    So I just want someone to tell me what is wrong with my following observation:
    I downloaded the source code of jdk 1.3.1 and read the file Hashtable.java, that contains the implementation code of Hashtables.
    Lots of methods (like get(), put(), contains(), ...) are declared public and synchronized. So far, all is good.
    But the function size() is defined as follows:
    public int size() {
         return count;
    where count is an instance variable defined as follows:
    * The total number of entries in the hash table.
    private transient int count;
    As the function size() is not synchronized, it can retrieve the value of "count" when another method is in the process of updating it.
    For instance, the method put() (that is synchronized) increments the variable "count" with this instruction:
    count++;
    But we know that operation on variable of type "int" are atomic, so this issue doesn't harm the thread safety of the code.
    But there is another issue with multithreading, that deals with caching of data in the working memory of each thread.
    Suppose the following scenario:
    1) Thread A calls method size(). This method reads the value of "count" and put it in the working memory of thread A.
    2) Thread B calls method put(). This method increments "count" using instruction "count++".
    3) Thread A calls method size() again. This method reads the value of "count" from the working memory of the thread, and this cached value may not be the updated value by thread B.
    As size() is not synchronized, or "count" is not declared "volatile", multiple threads may retrieve stale value, because the content of the thread working memory is not in sync with main memory.
    So, here I see a problem.
    Is there something wrong in this observation ?
    But

    Is there something wrong in this observation ?Unfortunately not, as far as I can tell.
    Recent analysis of java's synchronized support has revealed the danger in such unsynchronized code blocks, so it may have been a simple case that it wasn't realised that size is not thread-safe.
    If this is an issue, use Collections.synchronizedMap - in Sun's JDK 1.3, at least, all of the methods are synchronized, except for iterators.
    Regards,
    -Troy

  • Is there a way to change the Calendar date format in iCloud? It seems to default to the 'American' way even though on my iMac it is set to the 'British' way.

    My calendar in iCloud has the following format:
    1/12/2011 for the 12 January 2011
    I would like it to be as all my other Calendars were/are:
    12/1/2011 for 12th January 2011
    Any help gratefully accepted

    Welcome to the Apple Community.
    Click on the gear icon in the top right corner and select preferences from the menu that appears, you can adjust the date format from there.

  • Refer to Doc ID 825030 which talks about applying of patch for correction of date format in web adi. Is this patch can be applied on R12.1.3 instance as this patch released date is very old. Please suggest if there is another patch which be applied to cor

    Refer to Doc ID 825030 which talks about applying of patch for correction of date format in web adi. Is this patch can be applied on R12.1.3 instance as this patch released date is very old. Please suggest if there is another patch which be applied to correct the date format in web adi. currently the date is coming in number format.

    Hello,
    This document is for 11i Date Format Changes When Loaded Into Webadi (Doc ID 825030.1)
    use this document instead for R12 : Incorrect Date Format in Excel Sheet Generated Via WebADI (Doc ID 828253.1)
    <Moderator Edit - deleted MOS Doc content - pl do NOT post such content>
    Best Regards,
    Eric.

  • Is there any function module to convert the date format

    Dear ABAPers,
    Is there any function module to convert the date format from dd.mm.yyyy to dd-mmm-yyyy.
           I want to convert the date format from dd.mm.yyy to dd.mmm.yyy Eg.from 10.03.2008 to 10-mar-2009.
    Thanks & Regards,
    Ashok.

    hi,
    create custom function module or copy the below code in the report ..and use it
    the out put for below is :----Convert a DATE field into a full format date eg. March 23, 2000
    FUNCTION Z_CONVERT_DATE_INTO_FULL_DATE.
    ""Local interface:
    *"       IMPORTING
    *"             VALUE(DATE) LIKE  SY-DATUM
    *"       EXPORTING
    *"             VALUE(FORMATTED_DATE)
    *"       EXCEPTIONS
    *"              INVALID_DATE
    TABLES: TTDTG.
    DATA: BEGIN OF T_DATE,
            YYYY(4) TYPE C,
            MM(2) TYPE C,
            DD(2) TYPE C,
          END OF T_DATE.
    DATA: DAY(3) TYPE N.
    DATA: VARNAME LIKE TTDTG-VARNAME.
    IF DATE IS INITIAL.
      CLEAR FORMATTED_DATE.
      EXIT.
    ENDIF.
    check document date format
    CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
      EXPORTING
        DATE = DATE
      EXCEPTIONS
        PLAUSIBILITY_CHECK_FAILED = 1.
    IF SY-SUBRC NE 0.
      RAISE INVALID_DATE.
    ENDIF.
    MOVE DATE TO T_DATE.
    CONCATENATE '%%SAPSCRIPT_MMM_' T_DATE-MM INTO VARNAME.
    SELECT SINGLE * FROM TTDTG WHERE SPRAS = 'EN' AND VARNAME = VARNAME.
    WRITE T_DATE-DD TO DAY.
    CONCATENATE DAY ',' INTO DAY.
    CONCATENATE TTDTG-VARVALUE DAY T_DATE-YYYY INTO FORMATTED_DATE
      SEPARATED BY SPACE.
    ENDFUNCTION.
    the output is :--Convert a DATE field into a full format date eg. March 23, 2000
    Regards,
    Prabhudas

  • Is there any function module to convert date format?

    Is there any function module to convert date format from mm/dd/yyyy to dd.mm.yyyy or sy-datum?

    Hi,
    wirte statement converts any date fomat in system date fromat
        WRITE w_DateTO w_date_sys.
    Regards,
    Sriram

  • Is there any system variable for this date format 01/21/2004 18:00:32

    Hello,
    Is there any system variable for this date format 01/21/2004 18:00:32
    This is my Internal date format and my External date format is sy-datum.
    How can I validate....any suggestions will be apprecaited!
    Regards,
    Kittu

    Hello,
    Thank you very much for your response!
    My internal date format is 01/21/2004 18:00:32
    and external date format on selection-screen is sy-datum.
    My external format is stored in S_crtsp
    and internal format is stored in L_crtsp. (01/21/2004 18:00:32)
    I want to remove the time from the internal format and validate it aginst the external format.
    Any suggestions or brief explonation is appreciated...I apprecaite the help soo far...
    Regards,
    Kittu

  • I can't seem to find the data tab in format inspector...is there any other way to format numbers as currencies?

    I can't seem to find the data tab in format inspector...is there any other way to format numbers as currencies?

    Hi Aakritie,
    What version of Numbers are you using?
    What operating system?
    Your profile shows  Macbook Pro  (that is OS X) and also iOS
    I am using Numbers 3.2 on a Mac book Pro under OS X 10.9.2
    Format Inspector shows this when a cell is selected:
    Then choose a Data Format:
    Then:
    Regards,
    Ian.

  • List all of the existing column and there column format and data format?

    Hello Gurus,
    I am new to OBIEE and i have a requirement to verify the column format and data format for all of the existing column while generating a analysis report. Is there any way i can list down all of the columns which are exposed and list there column format and data format?
    For checking the individual column properties i know there is an option called 'Column Properties' but want to know all in once go.
    Kindly help me and thanks in advance.
    Thanks

    I don't think you have anything in answers to get that, Go to Repository and Utilities -> Generate Metadata Dictionary that will give columns and datatype.
    Award points if it helps
    ~Srix

Maybe you are looking for

  • "Adobe Photoshop CS5 has encountered a problem and needs to close."

    I get this error everytime I try to launch Photshop CS5. The startup screen appears but it stops at "Starting Plugins... Scripting support", then it gives that message^(along with don't send and send error report, of course). Specs: XP Pro SP3 E6750

  • Mapping text in smartforms

    How can i map the <b>header text</b> or <b>item text</b> in a smartforms .

  • Safari upgrade: images/icons not loading

    (apologies, I posted this on another thread by mistake) Everything went just fine until yesterday. I have no idea why Safari stopped loading images on websites. Safari and all of its plugins are up to date. Snow Leopard is up to date. Things tried so

  • Use J2EE CAS COM Bridge locally for non visual components

    if you only have non visual java-classes which you want to access locally through COM, you should use J2EE CAS COM Bridge. this is a very powerfull component, that makes it very easy to use about ANY java-class in VC++, VB, ASP and VBScripts. Some pe

  • Function definition question

    Hi all, I am a first time poster, long time Flash user, who is trying to wrap his head around AS3. When writing functions, I am unclear on on the part that goes inside the parentheses.  For instance, I have see some functions that say: function XXXXX