Home » Java » date – Java thread hangs when I add the code to get time difference-Exceptionshub

date – Java thread hangs when I add the code to get time difference-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

As part of my code I get time difference between two fields of an object and put it in a Map. Several times per second new payloads are created and this code is run to make new Maps.

if("deliver".equalsIgnoreCase(type) && "COURIER".equalsIgnoreCase(c))
            attributes.put("pickupToDropTime", ChronoUnit.MINUTES.between(payload.getPickingAt().toInstant(),payload.getDeliveredAt().toInstant()));

The problem is the code hangs after some minutes of running. When I replace the value part with a constant value it runs fine.

I tried using other time related classes but still the same happens

TimeUnit.MINUTES.toSeconds(payload.getDeliveredAt().getTime() - payload.getPickingAt().getTime())
How to&Answers: