I have a Calendar object that is being passed to indicate timezone when I insert a row in the database:
private long insertTime() {
statement.setTimestamp(index, new java.sql.Timestamp(Instant.now().toEpochMilli()),
Calendar.getInstance(TimeZone.getTimeZone(TIME_ZONE)));
}
I was suggested to create private static calendar object in the class and use it:
private static final Calendar = Calendar.getInstance(TimeZone.getTimeZone(TIME_ZONE));
...
...
...
private long insertTime() {
statement.setTimestamp(index, new java.sql.Timestamp(Instant.now().toEpochMilli()), calendar);
}
Both code works so I am not sure what is the value of changing my code to second one. Only possible value I can see is that this code runs quite often (multiple times in minutes), so instantiating calendar object multiple times is not good practice. But does it make a lot of difference?
EDIT: this calendar
object is only used for this method once.