0

I have the following lines of code in my application:

return "Service is alive since: " + TimeUnit.MILLISECONDS.toMinutes(mxBean.getUptime()) + " minutes";

It uses the following package:

import java.util.concurrent.TimeUnit;

My application is a web application. Does it means that I have something wrong logically if I use something from concurrent package at a web application?

  • As an old hardened C/C++ programmer I have to wonder at Java people who import code which has function names longer than the math required to do it inline. ms/1000/60 isn't it? – Zan Lynx Sep 5 '13 at 22:01
1

Using TimeUnit.MILLISECONDS.toMinutes(...) is fine as it doesn't actually invoke any threading behaviour (which would be incorrect in a Java EE container). It's part of core Java, so no overheads.

| improve this answer | |
0

I can't see any problem with this, and in fact using TimeUnit.MILLISECONDS.toMinutes(...) was the solution to the SO question that I found when googling "java convert milliseconds to minutes".

If you were in a constrained environment where you were worried about the size of your deployment, you might need to try cutting out any packages or jars that you don't need, but since java.util.concurrent is part of core Java, removing it would take some work.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.