Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can Threads affect Date Objects ??

 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Hoping someone might be able to offer a suggestion as to why I'm getting some very odd behaviour... In short it seems when I access a Date object through a seperate Thread.. the Date is being modified... somehow...??/

Basically my scenario is that I'm developing a JSF based app that uses multiple Threads to seperate the processing of my data to give response back to the user.. I have a ArrayList<MyObject> and MyObject contains a java.util.Date, say called myDate.... I have a kind of wizard approach going on where the user can upload a text file for parsing.. I then show the results which they can modify certain parts, and then they can run another process to process and persist the data to the database.

All is good until I get to the final stage where I'm about to persist the data.. The first set of objects (about 20) in my ArrayList 'lose' their Time information from the Date.. i.e the time will be 0:00:00..

Now I've got a Test package which calls the routine that generates this ArrayList of objects, and after the test I go through the list outputting a toString() on each object.. All the dates are there and correct.. So the passes...

So back to testing using the webapp... As I said I'm using JSF and I've also done a test where as soon as the user clicks on the process button.. I again go through the List and output each item as its toString() and thats OK.. BUT the next part is where I create a new Thread and immediately, actually in the constructor of the Thread (Runnable inner class) ... I AGAIN go through the list... and lo and behold the first 30 or so objects in the exact same list seem to have had their Time data stripped from the Data..

Heres an example of my toString() output...

[SCHEDULE IMPORT ELEMENT] 2008-08-01
[SCHEDULE IMPORT ELEMENT] 2008-08-02
[SCHEDULE IMPORT ELEMENT] 2008-08-03

All those are incorrect... The following are what I expect, and what is output both in my Test package AND at the moment before I setup a Thread...

[SCHEDULE IMPORT ELEMENT] Sun Aug 03 05:00:00 BST 2008
[SCHEDULE IMPORT ELEMENT] Sun Aug 04 05:00:00 BST 2008
[SCHEDULE IMPORT ELEMENT] Sun Aug 05 05:00:00 BST 2008


Any thoughts here greatly appreciated - I must admit this is quite beyond me as to whats happening...
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it isn't just loosing the time information, it is also printing out in the wrong format and with the wrong dates?

Can you make a simple multi-threaded application (a SSCCE) that duplicates the behavior - leaving JSF out of it. If you can post that code then we can see the issue.
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry chaps, its not the threading.. , the problems are down to the JSF side.. specifically the Converters...

So thanks for reading.. Sorry for wasting anyones time...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic