1

I want to create a countdown class, which will countdown to a later, desired date(using only hours, seconds, and minutes, other stuff not important) from now. In a GUI I want to show the user the remaining time, updating every second with a Timer.

The problem is: if the user chooses a date late enough, for example: 23 hours 59 minutes 59 seconds till the countdown ends, that means I have to call LocalDateTime.now() more than 80000 times. I read LocalDateTime is immutable, so I expect my actualDate = LocalDateTime.now() will leave a tons of unused objects back to the GC, which is sloppy. Is there a way around this with using only LocalDateTime?

Newbie1001
  • 131
  • 11
  • https://stackoverflow.com/questions/14393423/how-to-make-a-countdown-timer-in-java – Darshan Mehta Jul 29 '17 at 08:09
  • What is the problem you have? And why do you not want to use a timer? – Progman Jul 29 '17 at 10:57
  • I want to use a timer, with at least a variable storing the remaining seconds till a programmed shutdown. But sooner or later it will be out of sync, so I must call something like `somedate = LocalDateTime.now()` frequently, which I do not think is a good idea, as I mentioned before, because `somedate` is immutable.There has to be a better solution. – Newbie1001 Jul 30 '17 at 08:31

0 Answers0