Java Calendar, acts differently OSX Windows - java

Basically i have built an appointment scheduler webapp using java servlets.
It relies heavily on javas Calendar.
The whole thing was developed on my macbook running mountain lion with jdk 1.6.
Now when testing it on my pc i have had some strange results.
Running:
System.out.println("selected = "+selected);
Calendar now = Calendar.getInstance();
System.out.println("a "+now.getTime());
now.setTimeInMillis(selected);
System.out.println("b "+now.getTime());
now.set(Calendar.MILLISECOND,0);
now.set(Calendar.SECOND,0);
now.set(Calendar.MINUTE,0);
now.set(Calendar.HOUR_OF_DAY,6);//start from 6am
System.out.println("d "+now.getTime());
now.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
System.out.println("e "+now.getTime());
on the PC will output:
selected = 1355835600000
a Wed Dec 19 19:35:36 EST 2012
b Wed Dec 19 00:00:00 EST 2012
d Wed Dec 19 06:00:00 EST 2012
e Sun Dec 23 06:00:00 EST 2012
Yet on the mac it will output:
selected = 1355835600000
a Wed Dec 19 19:33:57 EST 2012
b Wed Dec 19 00:00:00 EST 2012
d Wed Dec 19 06:00:00 EST 2012
e Sun Dec 16 06:00:00 EST 2012
As we can see here, if i build a table representing a weekly schedule off these values, the mac will start at 6am on the sunday contained in the current week.
But the pc will start at 6am on the sunday contained in the next week.
Which means any appointments i create are out of sync on the pc (different days to whats expected)
note: the pc has been tested with both jdk1.6 and jdk1.7
Does anyone know any solutions or reasons behind this?
Thanks

Possibly, this is a locale/timezone problem which might differ on both machines.
Make sure that both instances use the same locale by hard coding it for example:
Calendar.getInstance(Locale.US);
else getInstance() would use the default locale of your system.

Related

Unable to schedule a TimerTask a long time in advance

Heavily edited/updated:
I am trying to schedule a task a long time in advance. I believe it is doing something to the process because it thinks it is not going to do anything else.
I should have used HOUR_OF_DAY for 24 hour time instead of hour, but still doesn't work correctly.
New code:
public class OtherMainClass {
private static Timer timer;
private static Calendar cal;
public static void main(String[] args) throws InterruptedException {
cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
cal.set(Calendar.HOUR_OF_DAY, 8);
cal.set(Calendar.MINUTE, 0);
System.out.println("Changed to: " + cal.getTime());
timer = new Timer();
System.out.println("current time is: " + Calendar.getInstance().getTime());
System.out.println("Scheduled for: " + cal.getTime());
timer.schedule(new MyTimerTask(), cal.getTime());
timer.schedule(new MyTimerCheckTask(), 0, 1000*60*10);
}
public static class MyTimerTask extends TimerTask {
#Override
public void run() {
System.out.println("in run at: " + Calendar.getInstance().getTime());
}
}
public static class MyTimerCheckTask extends TimerTask {
#Override
public void run() {
System.out.println("cal at: " + Calendar.getInstance().getTime() + " is: " + OtherMainClass.cal.getTime());
}
}
}
Commandline output (following "is:" is the calendar object passed into the schedule.):
Changed to: Fri Feb 14 08:00:41 GMT 2020
current time is: Thu Feb 13 23:25:41 GMT 2020
Scheduled for: Fri Feb 14 08:00:41 GMT 2020
cal at: Thu Feb 13 23:25:41 GMT 2020 is: Fri Feb 14 08:00:41 GMT 2020
cal at: Thu Feb 13 23:35:41 GMT 2020 is: Fri Feb 14 08:00:41 GMT 2020
cal at: Thu Feb 13 23:45:41 GMT 2020 is: Fri Feb 14 08:00:41 GMT 2020
cal at: Thu Feb 13 23:55:41 GMT 2020 is: Fri Feb 14 08:00:41 GMT 2020
cal at: Fri Feb 14 09:39:27 GMT 2020 is: Fri Feb 14 08:00:41 GMT 2020
in run at: Fri Feb 14 09:39:27 GMT 2020
Note the very interesting run at the end, as well as the other task running. I clicked on commandline, which turned it into select mode, then control-c to exit that, then a few seconds later, it did both Tasks. (It should have run long before I clicked on commandline.
Java version from java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.242-b08, mixed mode)
OS: Windows 10
I ran a test stating Friday around 11:30. I changed the windows sleep settings set to 1 hour (Start -> Settings -> System -> Power & sleep). Since Friday 8:00 had passed, I changed the day to Saturday. I also changed the repeated interval to every half hour 3*1000*60*10, since I wanted to limit the lines of output. I ran the code in 5 different Command Prompts and started them at around 11:30 Friday:
No QuickEdit Mode. The program was running and I had to Crtl-c to stop it. No printout to the screen after sleep initiated. (Admittedly I didn't wait to see if it would print the 8 o'clock message after some time, because it seemed pointless.)
QuickEdit Mode. Did not click inside the screen. Same as 1.
QuickEdit Mode. Clicked inside the screen and immediately cancelled with Ctrl^c. The prompt top bar changed to "Select Command Prompt.." and went back to "Command Prompt..". Same as 1.
QuickEdit Mode. Clicked inside the screen and highlighted some test. The prompt top bar changed to "Select Command Prompt". There was absolutely no printout after that until I pressed Ctrl^c and the printouts were as if I had just started the program and it just printed the below. However I did not just exit the program, and it resumes the 30 min interval printout, as you can see from the below:
QuickEdit Mode. Clicked inside the screen (that's all). The prompt top bar changed to "Select Command Prompt". Same as 4.
This is the result of 4 and 5, that only started printing after i exited "Select Command Prompt"-mode at 9:43 on Saturday:
Changed to: Sat Feb 15 08:00:16 CET 2020
current time is: Sat Feb 15 09:49:13 CET 2020
Scheduled for: Sat Feb 15 08:00:16 CET 2020
in run at: Sat Feb 15 09:49:13 CET 2020
cal at: Sat Feb 15 09:49:13 CET 2020 is: Sat Feb 15 08:00:16 CET 2020
cal at: Sat Feb 15 10:19:13 CET 2020 is: Sat Feb 15 08:00:16 CET 2020
cal at: Sat Feb 15 10:49:13 CET 2020 is: Sat Feb 15 08:00:16 CET 2020
cal at: Sat Feb 15 11:19:13 CET 2020 is: Sat Feb 15 08:00:16 CET 2020
...
I ran another test with the windows sleep setting set to "Never". Since Saturday 8:00 had passed, I changed the day to Sunday. I again ran the code in 5 different Command Prompts and started them at around 15:30 Saturday:
No QuickEdit Mode. Worked without issues. See below.
QuickEdit Mode. Did not click inside the screen. Same as 1.
QuickEdit Mode. Clicked inside the screen and immediately cancelled with Ctrl^c. The prompt top bar changed to "Select Command Prompt.." and went back to "Command Prompt..". Same as 1.
QuickEdit Mode. Clicked inside the screen and highlighted some test. The prompt top bar changed to "Select Command Prompt". There was absolutely no printout after that. Until I pressed Ctrl^c and the printout was identical to the test above.
QuickEdit Mode. Clicked inside the screen (that's all). The prompt top bar changed to "Select Command Prompt". There was absolutely no printout after that.
Result:
Changed to: Sun Feb 16 08:00:31 CET 2020
current time is: Sat Feb 15 15:35:31 CET 2020
Scheduled for: Sun Feb 16 08:00:31 CET 2020
cal at: Sat Feb 15 15:35:31 CET 2020 is: Sun Feb 16 08:00:31 CET 2020
cal at: Sat Feb 15 16:05:31 CET 2020 is: Sun Feb 16 08:00:31 CET 2020
..snip..
cal at: Sun Feb 16 07:05:31 CET 2020 is: Sun Feb 16 08:00:31 CET 2020
cal at: Sun Feb 16 07:35:31 CET 2020 is: Sun Feb 16 08:00:31 CET 2020
in run at: Sun Feb 16 08:00:31 CET 2020
cal at: Sun Feb 16 08:05:31 CET 2020 is: Sun Feb 16 08:00:31 CET 2020
The answer by Shaun Rowan to Why is my command prompt freezing on Windows 10? you provided mentions:
whenever you click on a command window in windows 10, it immediately halts the application process when it attempts to write to the console
So it doesn't seem to be a bug in the Command Prompt either, rather it's a feature.
As per Will my Window 10 apps continue to update or download on sleep or hibernation mode? by A. User:
Sleep is a power-saving state that allows a computer to quickly resume full-power operation (typically within several seconds) when you want to start working again. Putting your computer into the sleep state is like pausing a DVD player—the computer immediately stops what it’s doing and is ready to start again when you want to resume working.
If you're very interested in Windows sleep modes TechRepublic has an article on Investigating Sleep states in Windows 10 describes the 6 stages of sleep, from when the (processor clocks are stopped) -> (the processor shuts off to save power) -> (other chips on the motherboard may shut off)
Conclusion:
If you want your java program to keep executing, ensure your Command Prompt window is not in "Select Command Prompt.."-mode and also ensure that your computer does not enter sleep mode, as either of these will halt execution of the program.

opc ua client implementation using eclipse milo

I am trying to do the implementation of opc ua client using eclipse milo sdk and the reference link am using is:
https://community.hortonworks.com/questions/176894/opc-ua-client-performance-with-eclipse-milo.html
for the Publish/Subscribe code since am having multiple nodes am not able to make out the data that I get corresponds to which node id and also the timestamp I am getting am not able to make out its in which format.
Item: org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaMonitoredItem#2b2c39b1
Value: DataValue{value=Variant{value=11}, status=StatusCode{name=Good, value=0x00000000, quality=good},
sourceTime=DateTime{utcTime=131771575305048867, javaDate=Fri Jul 27 15:02:10 IST 2018},
serverTime=DateTime{utcTime=131771575305048867, javaDate=Fri Jul 27 15:02:10 IST 2018}}
and when am using Async Read code am not getting timestamp.
[DataValue{value=Variant{value=3},
status=StatusCode{name=Good, value=0x00000000, quality=good}, sourceTime=DateTime{utcTime=0, javaDate=Mon Jan 01 05:30:00 IST 1601}, serverTime=DateTime{utcTime=0, javaDate=Mon Jan 01 05:30:00 IST 1601}},
DataValue{value=Variant{value=11}, status=StatusCode{name=Good, value=0x00000000, quality=good}, sourceTime=DateTime{utcTime=0, javaDate=Mon Jan 01 05:30:00 IST 1601},
serverTime=DateTime{utcTime=0, javaDate=Mon Jan 01 05:30:00 IST 1601}},
DataValue{value=Variant{value=8}, status=StatusCode{name=Good, value=0x00000000, quality=good},
sourceTime=DateTime{utcTime=0, javaDate=Mon Jan 01 05:30:00 IST 1601}, serverTime=DateTime{utcTime=0, javaDate=Mon Jan 01 05:30:00 IST 1601}}]
can anyone give me some idea on where am going wrong?
It might be easier to understand if you started with the examples from Milo itself, rather than a random benchmark someone wrote using Milo that you happened to stumble across.
Check out the examples:
Subscribe Example
Read Example

Trying to list strings in a config sectiong

Okay I don't know how to explain this but if you look a
Players:
_Brand0n_:
'Fourm Link:': 'Null'
'Registered:': 'No'
'GamePoints:': '0'
'UUID:': 94bad256-7fa0-49c6-add1-50b61a854dc3
Reports:
'#R:': '0'
'TheeLux:': Hacking Time: Fri Jul 22 12:21:35 CDT 2016'
'Adam_Hall:': Hacking Time: Fri Jul 22 12:21:35 CDT 2016'
I need to be able to take the reports from TheeLux and Adam_Hall and print an msg saying
Adam_Hall: Hacking - Time: Fri Jul 22 12:21:35 CDT 2016
But I don't know how to take however many configuration sections and make them into strings ext. If this is confusing please post a comment and I'll try and clarify.

ews-java-api: Error on item update: At least one recipient isn't valid

I am working on a tool which uses ews-java-api to create, update and delete calendar items in Outlook agenda. It has been working fine, but now sometimes when it tries to update some calendar item, I get following error:
microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: At least one recipient isn't valid., A message can't be sent because it contains no recipients.
at microsoft.exchange.webservices.data.core.response.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:278)
at microsoft.exchange.webservices.data.core.response.ServiceResponse.throwIfNecessary(ServiceResponse.java:267)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:165)
at microsoft.exchange.webservices.data.core.ExchangeService.internalUpdateItems(ExchangeService.java:691)
at microsoft.exchange.webservices.data.core.ExchangeService.updateItem(ExchangeService.java:762)
at microsoft.exchange.webservices.data.core.service.item.Item.internalUpdate(Item.java:279)
at microsoft.exchange.webservices.data.core.service.item.Item.update(Item.java:400)
at be.vrt.quintiqexchange.main.QuintiqAdapter.insertUpdateCalendarItems(QuintiqAdapter.java:879)
at be.vrt.quintiqexchange.main.QuintiqAdapter.updateCalendarItems(QuintiqAdapter.java:796)
at be.vrt.quintiqexchange.main.QuintiqAdapter.run(QuintiqAdapter.java:286)
at java.lang.Thread.run(Thread.java:745)
Recently all the exchange accounts have been migrated from local Outlook servers to Office365 cloud servers. Maybe this has something to do with it? Or anybody have any idea on what is going wrong?
Following code is to perform the update for an item:
Item it = alitems.get(i);
...
it.update(ConflictResolutionMode.AlwaysOverwrite);
Following is the url being used to access office365 ews:
exchangewebservice = https://outlook.office365.com/EWS/Exchange.asmx
Thanks in advance
Edit: I use ews-java-api version 2.0
Edit: Here you can see that the error occurs on one line and than the next line, with the same recipient it doesn't occur...
microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: At least one recipient isn't valid., A message can't be sent because it contains no recipients.
at microsoft.exchange.webservices.data.core.response.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:278)
at microsoft.exchange.webservices.data.core.response.ServiceResponse.throwIfNecessary(ServiceResponse.java:267)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:165)
at microsoft.exchange.webservices.data.core.ExchangeService.internalUpdateItems(ExchangeService.java:691)
at microsoft.exchange.webservices.data.core.ExchangeService.updateItem(ExchangeService.java:762)
at microsoft.exchange.webservices.data.core.service.item.Item.internalUpdate(Item.java:279)
at microsoft.exchange.webservices.data.core.service.item.Item.update(Item.java:400)
at be.vrt.quintiqexchange.main.QuintiqAdapter.insertUpdateCalendarItems(QuintiqAdapter.java:880)
at be.vrt.quintiqexchange.main.QuintiqAdapter.updateCalendarItems(QuintiqAdapter.java:703)
at be.vrt.quintiqexchange.main.QuintiqAdapter.run(QuintiqAdapter.java:283)
at java.lang.Thread.run(Thread.java:745)
WARN be.vrt.quintiqexchange.main.QuintiqAdapter - At least one recipient isn't valid., A message can't be sent because it contains no recipients.by UPDATE for subject: on Thu Jun 23 14:00:00 CEST 2016 Thu Jun 23 19:00:00 CEST 2016 of user name.lastname#domain.com
INFO be.vrt.quintiqexchange.main.QuintiqAdapter - Appointment updated for subject: NIET DAG on Fri Aug 05 10:00:00 CEST 2016 Fri Aug 05 18:00:00 CEST 2016 of user name.lastname#domain.com
INFO be.vrt.quintiqexchange.main.QuintiqAdapter - Appointment updated for subject: PROEF st5 on Mon Aug 22 10:00:00 CEST 2016 Mon Aug 22 20:30:00 CEST 2016 of user name.lastname#domain.com
This means that the recipient isn't really the issue, I guess...
p.s. I replaced the original mailaddress but believe me, it's a correct mailadres :)
In my case, if the address is not properly trimmed and has any whitespace characters at all, EWS vomits this exception up.

Cron Job Failure on GAE with java

I am working on project using GWT java GAE. In my project i have used cron job.
when i schedule its time like every 5 minutes, every 2 minutes in cron.xml then its working fine i will getting my ouput. but when i schedule it time like every 24 hours or every day 21:00 then cron job executed but its throw error :-
E 2015-11-03 20:18:10.825
com.slicktechnologies.server.cronjobimpl.ContractRenewalCronJobImpl ContractRenewallist: Date Before Adding Day03-Nov-2015
E 2015-11-03 20:18:10.832
com.slicktechnologies.server.cronjobimpl.ContractRenewalCronJobImpl ContractRenewallist: Today Date -30 Days DateSat Oct 03 23:59:59 UTC 2015
E 2015-11-03 20:18:10.832
com.slicktechnologies.server.cronjobimpl.ContractRenewalCronJobImpl ContractRenewallist: Today DateMon Nov 02 18:30:00 UTC 2015
E 2015-11-03 20:18:10.832
com.slicktechnologies.server.cronjobimpl.ContractRenewalCronJobImpl ContractRenewallist: Date After Setting the Time Mon Nov 02 23:59:59 UTC 2015
E 2015-11-03 20:18:10.833
com.slicktechnologies.server.cronjobimpl.ContractRenewalCronJobImpl ContractRenewallist: Date Before Adding Day03-Nov-2015
E 2015-11-03 20:18:10.833
com.slicktechnologies.server.cronjobimpl.ContractRenewalCronJobImpl ContractRenewallist: Today Date +30 Days DateWed Dec 02 18:30:00 UTC 2015
E 2015-11-03 20:18:10.833
com.slicktechnologies.server.cronjobimpl.ContractRenewalCronJobImpl ContractRenewallist: Date Before Adding One DayMon Nov 02 18:30:00 UTC 2015
E 2015-11-03 20:18:10.833
com.slicktechnologies.server.cronjobimpl.ContractRenewalCronJobImpl ContractRenewallist: Today Date +30 Days DateThu Dec 03 18:29:29 UTC 2015
E 2015-11-03 20:18:10.833
com.slicktechnologies.server.cronjobimpl.ContractRenewalCronJobImpl ContractRenewallist: In Contract List
E 2015-11-03 20:18:10.833
com.slicktechnologies.server.cronjobimpl.ContractRenewalCronJobImpl ContractRenewallist: Date After Adding One DateMon Nov 02 23:59:59 UTC 2015
I 2015-11-03 20:18:11.146
This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.
Any help
Thanks in advance
The message about starting a new instance is not an error, it's just an informational message, expected when app instances are dynamically created (note the i marking):
GAE automatically stops dynamic instances after a period of inactivity (of at least 15 minutes) and start new instances on demand. Your app instance is not idle long enough when the job is scheduled every 2 or 5 minutes because of the cron job itself, but it may be when running the job daily.
More details in here.
You can see the message even when running the job every 2 or 5 minutes if, for example, you stop your instance manually.

Categories

Resources