A
aquafresh3
Hello,
I have read a lot of post and java tutorial and API about Calendar but
It seems I missed something.
I program a kind of cleaner scheduler in setting specific delay
between the clean.
For that I have got a DB in which I store the delay between each
clean.
First I calculate the new date of the cleaning by getting an instance
of the Calendar object and adding to it the delay like this:
nextClean = Calendar.getInstance();nextClean.add(Calendar.SECOND,
dbClean.getDelay());
And I store this value inside a Hashtable.
Then in a thread I scan the time until I reach the cleaning date like
in the following code:
while (running) {if (cleaningRequestorCollection.isEmpty()) {try {//
Checks each clean time against the current timeHashtable cleanTimes =
cleaningCalculator.getCleanTimes();synchronized (cleanTimes)
{Enumeration enum = cleanTimes.keys();Calendar current =
Calendar.getInstance(); while (enum.hasMoreElements()) {
Integer keyInt = (Integer) enum.nextElement(); int key =
keyInt.intValue(); Calendar calendar = (Calendar)
cleanTimes.get(keyInt); DBCleaningTypeImpl dbClean =
(DBCleaningTypeImpl) dbCleanings.get(keyInt); } // A cleaning
request message has to be sent if (current.after(calendar)) {
// New CleaningRequestor thread CleaningRequestor
cleaningRequestor = new CleaningRequestor(this, cleaningCalculator,
dbClean, clientConnection, cleanTopicName, adminUpdateTopicName);
cleaningRequestorCollection.put(new Integer(dbClean.getID()),
cleaningRequestor); cleaningRequestor.start(); } } } //
waits 5 seconds sleep(Labels.CLEANER_CLEANSCAN_INTERVAL); } catch
(InterruptedException ie) { Logger.logActivity(Labels.LOG_CLEANER
+ " CleaningScan thread interupted"); } }}
I gather the object record in the Hashtable and I obtain the date
(Calendar) of my cleaning date.
But the results show me a difference between the date registered first
in the Hashtable and the date gather in a second time from this
Hashtable.
A concrete exemple is:
The date is Thursday Feb 26 14:10:00
I choose an interval between the clean of 40 second so each 40 second
a cleaning is done
I store the cleaning date value : Thursday Feb 26 14:10:40
(so the next clean is at Thursday Feb 26 14:10:40)
But when I get the value in my thread from the Hastable thanks to this
line:
Calendar calendar = (Calendar) cleanTimes.get(keyInt);
I get the time Thursday Feb 26 15:10:40 so one hour more
As I am in GMT+1 I suppose that the reason and if I put my time to GMT
+-X I get a difference of +-X
So Is it normal if I get a Calendar.getInstance() I have a good time
but if I gather a value from my Hashtable then I get the time plus the
value of the GMT X?
Thank for any help
I have read a lot of post and java tutorial and API about Calendar but
It seems I missed something.
I program a kind of cleaner scheduler in setting specific delay
between the clean.
For that I have got a DB in which I store the delay between each
clean.
First I calculate the new date of the cleaning by getting an instance
of the Calendar object and adding to it the delay like this:
nextClean = Calendar.getInstance();nextClean.add(Calendar.SECOND,
dbClean.getDelay());
And I store this value inside a Hashtable.
Then in a thread I scan the time until I reach the cleaning date like
in the following code:
while (running) {if (cleaningRequestorCollection.isEmpty()) {try {//
Checks each clean time against the current timeHashtable cleanTimes =
cleaningCalculator.getCleanTimes();synchronized (cleanTimes)
{Enumeration enum = cleanTimes.keys();Calendar current =
Calendar.getInstance(); while (enum.hasMoreElements()) {
Integer keyInt = (Integer) enum.nextElement(); int key =
keyInt.intValue(); Calendar calendar = (Calendar)
cleanTimes.get(keyInt); DBCleaningTypeImpl dbClean =
(DBCleaningTypeImpl) dbCleanings.get(keyInt); } // A cleaning
request message has to be sent if (current.after(calendar)) {
// New CleaningRequestor thread CleaningRequestor
cleaningRequestor = new CleaningRequestor(this, cleaningCalculator,
dbClean, clientConnection, cleanTopicName, adminUpdateTopicName);
cleaningRequestorCollection.put(new Integer(dbClean.getID()),
cleaningRequestor); cleaningRequestor.start(); } } } //
waits 5 seconds sleep(Labels.CLEANER_CLEANSCAN_INTERVAL); } catch
(InterruptedException ie) { Logger.logActivity(Labels.LOG_CLEANER
+ " CleaningScan thread interupted"); } }}
I gather the object record in the Hashtable and I obtain the date
(Calendar) of my cleaning date.
But the results show me a difference between the date registered first
in the Hashtable and the date gather in a second time from this
Hashtable.
A concrete exemple is:
The date is Thursday Feb 26 14:10:00
I choose an interval between the clean of 40 second so each 40 second
a cleaning is done
I store the cleaning date value : Thursday Feb 26 14:10:40
(so the next clean is at Thursday Feb 26 14:10:40)
But when I get the value in my thread from the Hastable thanks to this
line:
Calendar calendar = (Calendar) cleanTimes.get(keyInt);
I get the time Thursday Feb 26 15:10:40 so one hour more
As I am in GMT+1 I suppose that the reason and if I put my time to GMT
+-X I get a difference of +-X
So Is it normal if I get a Calendar.getInstance() I have a good time
but if I gather a value from my Hashtable then I get the time plus the
value of the GMT X?
Thank for any help